Search code examples
c#azureazure-files

Simple File Transfer to Azure c#


Assuming I created a file share called "myshare" in Azure in a storage account called "mystorage" what would cause the code below to give this error message on UploadFromFile?

"The specified resource does not exist. RequestId:longstring Time:currenttime"

What am I missing to get this to upload?

static string connstring = "connection string copied from Azure access keys"
static string directorystring = "data being used is url in properties of file share in Azure, for this example it would be https://mystorage.file.core.windows.net/myshare"

DialogResult a = openFileDialog.ShowDialog();
        string[] filenames = openFileDialog.FileNames;
        foreach(string filename in filenames)
        {
            string filenameonly = Path.GetFileName(filename);
            CloudStorageAccount sa = CloudStorageAccount.Parse(connstring);
            CloudFileClient fc = sa.CreateCloudFileClient();
            CloudFileShare fs = new CloudFileShare(new Uri(directorystring));
            CloudFileDirectory fd = fs.GetRootDirectoryReference();
            CloudFile f = fd.GetFileReference(filenameonly);

                try
                {
                    f.UploadFromFile(filename);
                }
                catch (StorageException excep)
                {
                    MessageBox.Show(excep.RequestInformation.ExtendedErrorInformation.ErrorMessage.ToString());
                }

        }
    }

Solution

  • Modify the command

    CloudFileShare fs = new CloudFileShare(new Uri(directorystring));
    

    with

    CloudFileShare fs = fc.GetShareReference("share name");