将Json文件写入Azure文件共享

问题描述 投票:0回答:1

我有一个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数据,我需要将其直接写入文件共享而不创建任何本地文件。

c# json azure azure-storage fileshare
1个回答
0
投票

您几乎在那里:)。接下来要做的就是获取CloudFile的引用,并在其上调用UploadText方法。

CloudFile file = rootDir.GetFileReference("xyz.json");
file.UploadText(Json);
© www.soinside.com 2019 - 2024. All rights reserved.