asp.net-使用FileUpload上载到Windows Azure

asp.net-使用FileUpload上载到Windows Azure,asp.net,azure,Asp.net,Azure,在使用ASP.Net在Windows Azure上上载blob文件时,我从这里获得了以下代码: // Retrieve storage account from connection string. CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString")); // Create the b

在使用ASP.Net在Windows Azure上上载blob文件时,我从这里获得了以下代码:

// 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);
}
此代码工作正常,但我需要的是在ASP.Net中使用FileUpload控件上载文件。我需要更改路径,并将其替换为FileUpload上的文件路径。但我在研究中发现,文件上传不会返回文件的完整路径。文件上传是否由FileUpload完成?我不知道如何用FileUpload上传。有人能帮我吗?

试试这个:

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

if (FileUpload1.HasFile)
{
    blockBlob.Properties.ContentType = FileUpload1.PostedFile.ContentType;
    blockBlob.UploadFromStream(FileUpload1.FileContent);
}
解决了我的问题:

我替换了代码

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

fileASP
FileUpload
控件的ID。现在工作正常。

解决了我的问题:

我替换了代码

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


fileASP
FileUpload
控件的ID。它现在可以正常工作。

解决方案中缺少一些细节。我想到了内容类型。您的解决方案中缺少一些细节。我想到了内容类型。如果您使用FileUpload控件,则需要了解100 MB aspnettemp的限制。请参阅。如果您正在使用FileUpload控件,则需要注意100MB aspnettemp限制。看见