2

I've got this code from here on uploading blob files on Windows Azure with ASP.Net:

// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    CloudConfigurationManager.GetSetting("StorageConnectionString"));

// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");

// Create or overwrite the "myblob" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(@"path\myfile"))
{
    blockBlob.UploadFromStream(fileStream);
}

this code is working fine, but what I need is uploading of file with FileUpload control in ASP.Net. I need to alter the path, and replace it with the path of the file that is on FileUpload. But what I found out in my research is that the FileUpload will not return the full path of the file. Is there anyway that the uploading of file is done by the FileUpload? I don't know how to upload it with FileUpload. Can anyone help me?

1

3 Answers 3

4

Solved my Problem:

I replaced the code

using (var fileStream = System.IO.File.OpenRead(@"path\myfile"))
{
    blockBlob.UploadFromStream(fileStream);
}

to

using (fileASP.PostedFile.InputStream)
{
blockBlob.UploadFromStream(fileASP.PostedFile.InputStream);
}

the fileASP is the ID of the FileUpload control. It now works fine.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

if (FileUpload1.HasFile)
{
    blockBlob.Properties.ContentType = FileUpload1.PostedFile.ContentType;
    blockBlob.UploadFromStream(FileUpload1.FileContent);
}

Comments

0

There are a couple missing details in your solution. Content Type comes to mind. There is a solid solution on this question

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.