首页 > 解决方案 > MS Azure:无法将 Azure 云文件复制到另一个目录

问题描述

我正在尝试在同一个文件共享帐户中将云文件从一个目录复制到另一个目录,但面临问题。

代码:

以下是我正在使用的代码,以下文章(https://docs.microsoft.com/en-us/azure/storage/files/storage-dotnet-how-to-use-files#copy-files

public bool ArchiveTheFile(string filename)
    {
        bool fileCopied = false;
        try
        {
            var fileshare = ResolveCloudFileShare();
            if (fileshare.Exists())
            {
                CloudFileDirectory rootDir = fileshare.GetRootDirectoryReference();
                CloudFileDirectory dirSource = rootDir.GetDirectoryReference(ConfigurationManager.AppSettings["Azure.Storage.FileShare.Source"]);
                CloudFileDirectory dirArchive = rootDir.GetDirectoryReference(ConfigurationManager.AppSettings["Azure.Storage.FileShare.Destination"]);

                // Ensure that the directory exists.
                if (dirSource.Exists())
                {
                    // Get a reference to the file we created previously.
                    CloudFile sourceFile = dirSource.GetFileReference(filename);

                    // Ensure that the file exists.
                    if (sourceFile.Exists())
                    {
                        // Ensure that the directory exists.
                        if (dirArchive.Exists())
                        {
                            // Get a reference to the destination file.
                            CloudFile destFile = dirArchive.GetFileReference(filename);
                            destFile.StartCopy(sourceFile);fileCopied =true;
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
        }
        return fileCopied ;
    }

以下是错误:

无法使用CloudFile类的StartCopy()方法

1.错误截图:

在此处输入图像描述

GetFileReference() 返回的对象没有 StartCopy() 方法:

在此处输入图像描述

2.错误信息:

“CloudFile”不包含“StartCopy”的定义,并且找不到接受“CloudFile”类型的第一个参数的扩展方法“StartCopy”(您是否缺少 using 指令或程序集引用?

请注意:我已经在使用以下两个程序集参考:

使用 Microsoft.WindowsAzure.Storage;

使用 Microsoft.WindowsAzure.Storage.File;

标签: azureazure-storageazure-storage-filesazure-files

解决方案


将您的Microsoft.WindowsAzure.Storage软件包更新到最新版本或至少 5.0.2。直到版本 5.0.2 才支持StartCopyfor 。CloudFile


推荐阅读