Azure CloudFile - amp;quot;The specifed resource name contains invalid characters.amp;quot;(Azure CloudFile-amp;指定的资源名称包含无效字符。amp;报价;)
问题描述
我正在尝试将文件从Azure File Storage
下载到本地文件,并收到此异常:
"指定的资源名称包含无效字符。"
代码如下:
if (_cloudFileShare.Exists())
{
CloudFileDirectory rootDir = _cloudFileShare.GetRootDirectoryReference();
CloudFileDirectory tempDir = rootDir.GetDirectoryReference("temp");
if (tempDir.Exists())
{
var file = tempDir.GetFileReference(saveFrom);
file.DownloadToFile(saveTo, FileMode.Open);// OFFENDING LINE
}
}
saveTo
参数是一个字符串,值如下所示:
"C:UsersMeAppDataLocalTemp mpF2AD.tmp"
saveFrom
参数如下所示:
https://storageaccount.file.core.windows.net:443/fileshare/temp/tmpA2DA.tmp
我使用以下函数创建参数:
var saveTo = Path.GetTempFileName();
我做错了什么?我没有多少使用Azure的经验。
推荐答案
问题与您的saveFrom
变量有关。它应该只包含文件名,而不是整个URL。因此,如果您尝试下载的文件是tmpA2DA.tmp
,您的代码应该是:
var file = tempDir.GetFileReference("tmpA2DA.tmp");
请进行此更改,然后重试。它应该可以工作。
以下是我用来测试的完整代码:
static void FileDownloadTest()
{
var cred = new StorageCredentials(accountName, accountKey);
var account = new CloudStorageAccount(cred, true);
var client = account.CreateCloudFileClient();
var _cloudFileShare = client.GetShareReference("fileshare");
if (_cloudFileShare.Exists())
{
CloudFileDirectory rootDir = _cloudFileShare.GetRootDirectoryReference();
CloudFileDirectory tempDir = rootDir.GetDirectoryReference("temp");
if (tempDir.Exists())
{
var saveTo = System.IO.Path.GetTempFileName();
var file = tempDir.GetFileReference("tmpA2DA.tmp");
file.DownloadToFile(saveTo, FileMode.Open);
}
}
}
这篇关于Azure CloudFile-&;指定的资源名称包含无效字符。&;报价;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Azure CloudFile-&;指定的资源名称包含无效字符。&;报价;


- 如何用自己压缩一个 IEnumerable 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01