以编程方式下载 Azure 文件共享文档

Chr*_*her 3 c# asp.net fileshare azure azure-files

我正在参与一个项目,从 Azure 文件存储帐户下载文档 (.pdf) 的能力将非常有用。这可能吗?我目前只能将目录和目录的文件内容路径输出为字符串,但无法使用 Microsoft.Azure 命名空间访问这些路径上的文件。

其他详细信息:在 C#/ASP.NET 中,部署为 Azure Web 应用程序

谢谢。

C

Lee*_*Liu 6

对的,这是可能的。

这是一个演示供您参考:

我的文件共享和一张图片文件如下:

在此输入图像描述

我的代码如下:

    public static void DownloadFromFileStorage()
    {
        CloudStorageAccount account = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=leeliublob;AccountKey=OxxxxxxxxQSy2vkvSi/x/e9l9FhLqayXcbxxxxxJ5Wjkly1DsQPYY5dF2JrAVHtBozbJo29ZrrGJA==;EndpointSuffix=core.windows.net");
        CloudFileClient client = account.CreateCloudFileClient();


        //get File Share
        CloudFileShare cloudFileShare = client.GetShareReference("myfile");

        //get the related directory
        CloudFileDirectory root = cloudFileShare.GetRootDirectoryReference();
        CloudFileDirectory dir = root.GetDirectoryReference("Folder1");

        //get the file reference
        CloudFile file = dir.GetFileReference("1.PNG");

        //download file to local disk
        file.DownloadToFile("C:\\Test\\1.PNG", System.IO.FileMode.OpenOrCreate);

    }
Run Code Online (Sandbox Code Playgroud)

结果截图:

在此输入图像描述