locked
[Azure File Storage] Keep getting "The remote server returned an error: (404) Not Found" RRS feed

  • Question

  • Using Azure File Storage, I got error "The remote server returned an error: (404) Not Found" 

    The code is like:

     public void azureStorage()
     {
                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
                    CloudFileClient CloudFileClient = storageAccount.CreateCloudFileClient();
                    fileShare = CloudFileClient.GetShareReference("sharedfiles");
                    string policyName = "SharePolicy" + DateTime.UtcNow.Ticks;

                    //set permission and define policy   
                    SharedAccessFilePolicy sharedAccessFilePolicy = new SharedAccessFilePolicy()
                    {
                        SharedAccessExpiryTime = DateTime.UtcNow.AddHours(1),
                        Permissions = SharedAccessFilePermissions.Read | SharedAccessFilePermissions.Write
                    };
                    FileSharePermissions fsp = fileShare.GetPermissions();   <--------------------------Error Here
                    fsp.SharedAccessPolicies.Add(policyName, sharedAccessFilePolicy);
                    fileShare.SetPermissions(fsp);
                    //create SAS
                    sasToken = fileShare.GetSharedAccessSignature(new Microsoft.WindowsAzure.Storage.File.SharedAccessFilePolicy()
                    {
                        Permissions = SharedAccessFilePermissions.Read|SharedAccessFilePermissions.List| SharedAccessFilePermissions.Write,
                        SharedAccessExpiryTime = new DateTimeOffset(DateTime.UtcNow.AddDays(1))
                    });
    }

    I got the error when I tried to get the permission of the file share before I add new permission. That is really wired?

    Any suggestion?  Thanks


    • Edited by Md Shihab Tuesday, October 17, 2017 8:20 AM Edited title for clarity
    Tuesday, October 17, 2017 1:20 AM

Answers

  • Very sorry. I figured it out. I made the name of the share wrong. Spelling mistake!!!
    • Proposed as answer by Md Shihab Wednesday, October 18, 2017 7:13 AM
    • Marked as answer by vikranth s Sunday, October 22, 2017 12:31 PM
    Tuesday, October 17, 2017 9:11 PM

All replies

  • Where and how are you trying to run this code? Are you following any documentation to achieve this? If so, it’d help if you can share that.

    -----------------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.

    Tuesday, October 17, 2017 8:22 AM
  • Just want to initialize the Azure File Storage in one of the controller in ASP.NET Web API. I want to create or upload one of the dynamic created HTML page to the File Storage, then user can access the page from anywhere. 

    The file share has been created already when I logged in as the owner. 

    Any suggestion?

    Thanks,

    Tuesday, October 17, 2017 12:45 PM
  • And how can I create cloudfileclient with SharedAccessSignature Token?

    Like add the token in when I do CloudFileClient CloudFileClient = storageAccount.CreateCloudFileClient();

    Thx 

    Tuesday, October 17, 2017 2:06 PM
  • Either the share does not exist or you don't have permission to access it. Also, I see that your code is creating a SAS policy but the SAS token created at the end is not tied to any policy.

    Could you share the exception.ToString() output? It often has details that help when investigating issues like this.

    Tuesday, October 17, 2017 5:37 PM
  • Now I changed the code to:

                    

                    string ConnectionString = CloudConfigurationManager.GetSetting("StorageConnectionString");
                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConnectionString);
                    CloudFileClient CloudFileClient = storageAccount.CreateCloudFileClient();               

                    fileShare = CloudFileClient.GetShareReference("sharedfiles");//sharedfiles is existing

                    string policyName = "Policy" + DateTime.UtcNow.Ticks;
                    // define policy   
                    SharedAccessFilePolicy sharedAccessFilePolicy = new SharedAccessFilePolicy()
                    {
                        SharedAccessExpiryTime = DateTime.UtcNow.AddHours(1),
                        Permissions = SharedAccessFilePermissions.Read | SharedAccessFilePermissions.Write | SharedAccessFilePermissions.Create | SharedAccessFilePermissions.List
                    };
                    //Generate the shared access signature on the container, setting the constraints directly on the signature.
                    string sasContainerToken = fileShare.GetSharedAccessSignature(sharedAccessFilePolicy);

                    ...............

                    It is ok now. No error when calling GetSharedAccessSignature(sharedAccessFilePolicy). But I got the error again when I keep going

                        

                   CloudFileDirectory rootDirectory = fileShare.GetRootDirectoryReference();
                    try
                    {
                        cloudFileDirectory = rootDirectory.GetDirectoryReference("dir");
                        cloudFileDirectory.CreateIfNotExists();

                        CloudFileDirectory subFileDir = cloudFileDirectory.GetDirectoryReference("subdir");
                        subFileDir.CreateIfNotExists();

                        CloudFile cloudFile = subFileDir.GetFileReference(filename);

                        //upload file content string
                        cloudFile.UploadText(filenamecontent);
                        iRet = 1;
                    }
                    catch (Exception ex)
                    {

                       }

    I got "The remote server returned an error: (404) Not Found."

    Can you help?

    Thank you

    Tuesday, October 17, 2017 7:06 PM
  • It shows like "The remote server returned an error: (404) Not Found."
    Tuesday, October 17, 2017 8:26 PM
  • I mean the entire output of ToString, not just the exception message. There is information printed at the end of the storage exception that can help debug.
    Tuesday, October 17, 2017 8:38 PM
  • Very sorry. I figured it out. I made the name of the share wrong. Spelling mistake!!!
    • Proposed as answer by Md Shihab Wednesday, October 18, 2017 7:13 AM
    • Marked as answer by vikranth s Sunday, October 22, 2017 12:31 PM
    Tuesday, October 17, 2017 9:11 PM
  • Glad you got it sorted out. :)
    Wednesday, October 18, 2017 7:02 AM