我有一个Json数据,需要将其写入Azure文件共享名“ jsondata”中的Json文件。我需要将Json数据写入文件共享上名为“ xyz.json”的文件中。
基于参考,我具有以下用于FileShare的代码
string Json=JsonConvert.SerializeObject(info.contact);
Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(connectionString);
CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
// Get a reference to the file share we created previously.
CloudFileShare share = fileClient.GetShareReference("jsondata");
Task<bool> shareExistTask = Task.Run(async () => await share.ExistsAsync());
shareExistTask.Wait();
bool shareExist = shareExistTask.Result;
shareExistTask.Dispose();
if (shareExist)
{
CloudFileDirectory rootDir = share.GetRootDirectoryReference();
}
我在互联网上看到的所有示例都在谈论如何从本地存储的文件中获取数据并将其写入文件共享。但就我而言,我有一个Json数据,我需要将其直接写入文件共享而不创建任何本地文件。
您几乎在那里:)。接下来要做的就是获取CloudFile
的引用,并在其上调用UploadText
方法。
CloudFile file = rootDir.GetFileReference("xyz.json");
file.UploadText(Json);