在我的应用程序中,我正在尝试将文档上传到Azure blob存储。代码是:
// Namespaces for Azure
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
public ActionResult GetPdf(HttpPostedFileBase document)
{
int pdfocument = Request.ContentLength;
var doctype=Request.ContentType;
byte[] pdf = new byte[pdfocument];
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("Setting1"));
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("containername");
container.CreateIfNotExists();
var permissions = container.GetPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Blob;
container.SetPermissions(permissions);
string uniqueBlobName = "blobname";
CloudBlockBlob blob = container.GetBlockBlobReference(uniqueBlobName);
blob.Properties.ContentType = doctype;
blob.UploadByteArray(pdf);
}
当我构建我的应用程序时,我在container.CreateIfNotExists()
收到错误。错误是:
'Microsoft.WindowsAzure.StorageClient.CloudBlobContainer'不包含'CreateIfNotExists'的定义,并且没有扩展方法'CreateIfNotExists'接受类型'Microsoft.WindowsAzure.StorageClient.CloudBlobContainer'的第一个参数可以找到(你错过了吗?) using指令或程序集引用?)'。
我可以为该错误添加哪个命名空间?
答案 0 :(得分:7)
CreateIfNotExists是Azure库2.0版的一部分。
如果您使用的是1.7版StorageClient名称空间,则需要调用CreateIfNotExist(无复数)