Vs.Net C# Azure 文件存储无法为现有文件共享添加文件
Vs.Net C# Azure flle storage fails to add File for existing File Share
VS.NET C# 无法在 Azure 文件存储上为现有文件共享创建文件
我正在使用 Microsoft.WindowsAzure.Storage 库来访问 Azure 文件存储 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();
}
First SaveText(file1) 调用工作正常,Share & "file1" 已创建。
第二次 SaveText(file2) 调用,没有错误,没有创建“file2”。
相同的用户,相同的应用程序。
我使用的是 nuget 包 WindowsAzure.Storage,版本 9.3.3,和一个控制台项目(不是 .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();
}
}
}
如果还有其他问题或代码之间有任何差异,请告诉我。
VS.NET C# 无法在 Azure 文件存储上为现有文件共享创建文件
我正在使用 Microsoft.WindowsAzure.Storage 库来访问 Azure 文件存储 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();
}
First SaveText(file1) 调用工作正常,Share & "file1" 已创建。 第二次 SaveText(file2) 调用,没有错误,没有创建“file2”。 相同的用户,相同的应用程序。
我使用的是 nuget 包 WindowsAzure.Storage,版本 9.3.3,和一个控制台项目(不是 .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();
}
}
}
如果还有其他问题或代码之间有任何差异,请告诉我。