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://learn.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 :
Object returning by GetFileReference() do not have StartCopy() method :
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;
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.