VS.NET C#无法在Azure文件存储上为现有文件共享创建文件
我正在使用 Microsoft.WindowsAzure.Storage 库访问Azure File Storage API。我的方法创建文件共享并上传文件。创建文件共享后,它可以使用,但是当文件共享存在时,它会跳过文件上传。
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
public void SaveText( string fileName )
{
string accountName = "mylogs";
string key = @"dvjdjhsvdjfhvsjhdvfjhsvdfjhC2g==";
var storageAccount = new CloudStorageAccount(new StorageCredentials(accountName, key), true);
var share = storageAccount.CreateCloudFileClient().GetShareReference("test");
share.CreateIfNotExistsAsync().Wait();
var root = share.GetRootDirectoryReference();
root.GetFileReference(fileName).UploadTextAsync("mytext").Wait();
}
第一个SaveText( file1 )调用工作正常,共享和“ file1 ”已创建。 第二次SaveText( file2 )调用,没有错误,没有创建任何“ file2 ”。 同一用户,同一应用。
答案 0 :(得分:0)
我正在使用9.3.3版的nuget软件包WindowsAzure.Storage,并且在控制台项目(不是.net核心)下,它可以正常工作。
示例代码为打击(只需使用您的代码即可):
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using System;
namespace AzureFileTest
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
p.SaveText("file1"); //in the first call, file1 created and text uploads.
p.SaveText("file2"); //in the second call, file2 created and text uploads.
Console.WriteLine("done now");
Console.ReadLine();
}
public void SaveText(string fileName)
{
string accountName = "xxxxx";
string key = "xxxxxx";
var storageAccount = new CloudStorageAccount(new StorageCredentials(accountName, key), true);
var share = storageAccount.CreateCloudFileClient().GetShareReference("test");
share.CreateIfNotExistsAsync().Wait();
var root = share.GetRootDirectoryReference();
root.GetFileReference(fileName).UploadTextAsync("mytext").Wait();
}
}
}
请让我知道是否还有其他问题,或代码之间有任何区别。