2
votes

I am trying to copy a Cloud File from one directory to another, within same File-Share account but facing issue.

Code:

Below is the code I am using, following article ( 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 ;
    }

Below is the error :

Not able to use StartCopy() method of CloudFile class

1. Screenshot of error :

enter image description here

Object returning by GetFileReference() do not have StartCopy() method :

enter image description here

2. Error Message :

'CloudFile' does not contain a definition for 'StartCopy' and no extension method 'StartCopy' accepting a first argument of type 'CloudFile' could be found (are you missing a using directive or an assembly reference?

Please Note: I am already using below two assembly reference:

using Microsoft.WindowsAzure.Storage;

using Microsoft.WindowsAzure.Storage.File;

1
Any more details? I test it in my site and it works fine. How do you authenticate your source file?Joey Cai
I am authenticating using Access Key. I am not facing problem accessing the files. Issue Is: Code is not getting compiled because of the error. I am not able to see StartCopy() function of CloudFile object (destFile). Am I missing any Assembly/Reference here ?Sandeep Nandey
Are you sure you are referencing the right CloudFile? if you hover the mouse over CloudFile, what binary is it coming from?Saher Ahwal
Please tell us about the version of Storage SDK for .Net you're using.Gaurav Mantri
1. CloudFile is comming from Microsoft.WindowsAzure.Storage.File 2. Version : 4.3.0.0Sandeep Nandey

1 Answers

2
votes

Update your Microsoft.WindowsAzure.Storage package to latest version or at least 5.0.2. StartCopy for CloudFile is not supported until version 5.0.2.