2013-02-18 143 views
2

在我的应用程序中,我试图将文档上传到Azure blob存储。该代码是:什么是CreateIfNotExists的命名空间?

// 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”的第一个参数可以找到(你是否缺少使用指令或程序集引用?)'。

我可以为那个错误添加哪个命名空间?

回答

7

CreateIfNotExists是Azure库2.0版的一部分。

如果您使用的是1.7版StorageClient命名空间,那么你需要调用CreateIfNotExist(没有复数)

+0

罗布嗨,你的信息是correct.it的非常usefult到me.for这在浪费夫妇hours.Thanks一个的许多。 – PCSSCP 2013-02-18 11:02:46

+0

@PCSSCP,如果它解决了你的问题,请将其标记为答案。 – 2013-02-18 12:38:53

+0

费尔南多,我现在标记了它 – PCSSCP 2013-02-19 03:59:42

相关问题