locked
Save HttpPostedFile to Azure File Services network drive RRS feed

  • Question

  • I have set up a Mapped Network drive using Azure File Services in an Azure Cloud Service. This is mapped to Z: as per the instructions in Microsoft's documentation. However, when I attempt to save a file to the network store from my code, I receive an error message saying the network location is unavailable. 

    This is the code I am using:

            private IEnumerable<UploadedFile> UploadWholeFile(HttpContext context)
            {
                for (var i = 0; i < context.Request.Files.Count; i++)
                {
                    var file = context.Request.Files[i];
                    var fullPath = GetFilePath(file.FileName);
                    var extension = new FileInfo(fullPath).Extension.Substring(1);
    
                    if (!Regex.IsMatch(extension, FileUploadConfiguration.Current.AcceptedExtensionsPattern))
                    {
                        yield return UploadedFile.Failure(file.FileName, file.ContentLength, "Filetype not allowed");
                    }
                    else if (file.ContentLength > FileUploadConfiguration.Current.MaxSizeInBytes)
                    {
                        yield return UploadedFile.Failure(file.FileName, file.ContentLength, "File too big.");
                    }
                    else
                    {
                        file.SaveAs(fullPath);
                        yield return UploadedFile.Success(new FileInfo(fullPath));
                    }
                }
            }

    I have mapped the drive using the following commands:

    net use z: \\<account name>.file.core.windows.net\<share name> /u:<account name> <account key>

    If any one has any ideas on how to save a file to a mapped network drive, that would be incredibly helpful!

    Thank in advance.

    Monday, November 10, 2014 1:14 PM

Answers