0
對WPF不熟悉。當我點擊我的WPF應用程序中的一個按鈕時,我想上傳一張圖片到azure blob。我有以下代碼1-打開文件對話框,2- GetContainer類。 爲什麼這不起作用? 私人無效btnUpload_Click(對象發件人,RoutedEventArgs E) {Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment引發異常
// Configure open file dialog box
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.FileName = "Picture"; // Default file name
//dlg.DefaultExt = ".txt"; // Default file extension
dlg.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif"; // Filter files by extension
// Show open file dialog box
Nullable<bool> result = dlg.ShowDialog();
// Process open file dialog box results
if (result == true)
{
// Open document
string filename = dlg.FileName;//*********************ABOVE CODE OPENS FILES TO SELECT************************
}
}
{
string uniqueBlobName = Guid.NewGuid().ToString();
// Retrieve storage account from connection string.
CloudStorageAccount objStorage = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("DefaultEndpointsProtocol=https;AccountName=*********;AccountKey=************)
// Create the blob client.
CloudBlobClient objclient = objStorage.CreateCloudBlobClient();
// Retrieve a reference to a container.
CloudBlobContainer objContainer = objclient.GetContainerReference("rewardsimageblob");
// Create the container if it doesn't already exist.
objContainer.CreateIfNotExist();
// Retrieve reference to a blob named "uniqueBlobName"
CloudBlob blob = objContainer.GetBlobReference(uniqueBlobName);
// Create or overwrite the "uniqueBlobName" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(@"path\myfile"))
{
blob.UploadFromStream(fileStream);
}
}
}
謝謝,我已經做出了改變,但我得到一個錯誤「並不是所有的路徑返回值」 – user2631662
你'GetContainer'方法不'return'什麼。將'return objContainer;'添加到方法的末尾。 – ywm