upload image to azure blob storage c# ms crm plugin
Before reading this article, please go through the following article:
- Installation Of Azure SDK And Hulk Storage In Azure: Part 1
In this article, I'll tell you the uses of Azure Hulk Storage and how to use blob storage in ASP.NET Project. Firstly, create an ASP.Cyberspace project in Visual Studio, then open up Visual Studio and follow these steps:
Step 1: Open Visual Studio and select the File bill of fare, New, then Project.
Step 2: Get to Templates, Visual C#, then ASP.Net Web Application.
Step 3: In the proper noun section, give a proper name to project. Here I have given the name "Azure Hulk Storage".
Pace 4: Click on "OK" push to create a project.
In the following figure, choose "Empty" project.
Click "OK" button.
We can run into, in our projection, at that place are three types of categories items, properties, References, and Web.config.
Now nosotros need to install the Windows Azure Storage package for using Azure Storage Access and all supported classes.
Now go to the "TOOLS" menu, select "NuGet Package Manager", and select "Manage NuGet Packages for Solution".
In the following effigy get to the search box and type "azure". Afterwards this you lot will find the "Windows Azure Storage", click on "Install" push button.
Now in the post-obit figure, you can meet the installation of the "Windows Azure Storage".
Hither in the post-obit window,you will exist asked to install "Windows Azure Storage" for the current project, and so here we want to install the packages for current projection.
Merely click on "OK" push.
The installing process is going on.
Hither in the following figure, click on "I Have" button.
Now nosotros successfully installed the "Windows Azure Storage" (in the small reddish circle).
Click on "Shut" button.
Here we also demand to install the azure storage customer packages. So become to the search box, blazon the "Azure Storage Client". After typing, click on "Install" button.
Nosotros successfully installed the "Azure Storage Client" package also.
Click on "Shut" button.
Become to your project, here my project name is "Azure Blob Storage".
Right click on to projection, select "Add" and select "New Detail".
Here, I am going to create a Spider web Form, so select a Web Form in the listing and give the name to your Web Form; here I gave the name "MyForm" to my Web Course, you can give any name to your Web Form.
Click on "Add" button.
After creating a class, y'all tin can run across your project, where class will be created successfully with the name "MyForm.aspx"
In the "MyForm.aspx.cs" page, let me do some changes.
In the "MyForm.aspx.cs" page, I have added all namespaces which is minimum required.
Now we need "accountname" and "accesskey" to get continued with Azure Account, and then go to Azure portal.
Become to "Storage" option where I have created a Storage Business relationship with the name "nitindemostorage" in my previous commodity. You lot can visit my previous article of azure.
- Installation Of Azure SDK And Blob Storage In Azure: Role 1
Here, subsequently clicking "nitindemostroage" named Storage Account, go to bottom of the window and select "Manage Access Keys".
You will find the following window, copy the "Storage Account Name" and "Primary Access Key" from here,
Go back in your project and make some changes over there.
In the "accountname" and "accesskey" paste the copied item over in that location.
And make some other code over there for getting connections with Azure storage business relationship with "CloudStorageAccount" class object and at terminal convert your image into stream upload every bit in the post-obit image:
Code
- string accountname = "nitindemostorage" ;
- string accesskey ="8TeQ8Li/b5U75aSPeTUvmg6w6s6emWSC5KKksNR7hRmSS5GmxzY8wxXFxJtNlwnwSbvlWGAX07dnR0W8jrb+Og==" ;
- effort
- {
- StorageCredentialscreden = newStorageCredentials(accountname, accesskey);
- CloudStorageAccountacc = newCloudStorageAccount(creden, useHttps:true );
- CloudBlobClient customer = acc.CreateCloudBlobClient();
- CloudBlobContainercont = client.GetContainerReference("mysample" );
- cont.CreateIfNotExists();
- cont.SetPermissions(newBlobContainerPermissions
- {
- PublicAccess = BlobContainerPublicAccessType.Blob
- });
- CloudBlockBlobcblob = cont.GetBlockBlobReference("Sampleblob.jpg" );
- using (Stream file = System.IO.File.OpenRead(@ "D:\amit\Nitin sir\Nitinpandit.jpg" ))
- {
- cblob.UploadFromStream(file);
- }
- }grab (Exception ex)
- {
- }
I more thing, hither we need to create a Web App Profile for publishing our app into the cloud.
Simply get to "Spider web APPS" in your Azure Portal and click on "New" to add a new Web App.
Later clicking on "New", yous will meet the following window.
Go to "COMPUTE" option, select "Spider web APP", and select "QUICK CREATE".
In the URL section, you can write your Web App name. Here I accept given "nitinblobstoragedemo", if the entered name is right it will create a cheque sign (in blue color).
In the "APP SERVICE PLAN" click on "Default1 (East Asia, Shared)".
Click on "CREATE Spider web APP".
We accept created our Spider web App successfully. Later on doing this, we can encounter our created Spider web APP("nitinblobstoragedemo").
And it is in running way.
We make some code in the Web Config file likewise.
Hither in the <add value="MyForm.aspx"/>, "My Course" is my Web form.
In the "MyForm.aspx" you lot can give any message for output. Whenever yous build your project, the typed message volition be your output.
So, here in the div section I have given a bulletin, "Creating Hulk---Past Nitin Pandit".
Now we need to publish our created project in the deject. It will also save in the Azure Explorer. You can publish your project by two means. Here, I am going to discuss both means. Firstly, right click on your project. Here my projection is "AzureBlobStorage", so select the "Publish" option.
In the post-obit figure, you can see "nitinblobstoragedemo" is my Web App name, which nosotros have created in the starting. Select your Web APP profile and click "Publish" push.
After clicking on "publish" push button the project would publish on cloud too as in your Azure Explorer. The second manner to publish your projection is to go for cloud. Yous can download your contour from the Azure business relationship in your Web Apps. For this click on your Web App profile, in the Publish your app section, click on "Download the publish profile".
Afterwards clicking, your contour volition be downloaded in your system.
After this, now nosotros can see the condition of our publishing. So my "nitinblobstoragedemo" app service published successfully.
Now build your project and get your output.
Now run the application, printing F5.
So, finally we got our output.
We tin run into the changes of this in our Azure Explorer.
Now refresh the Azure Explorer to bank check your prototype.
"Sampleblob.jpg" is my epitome which is generated by programming,
Right click on prototype and open up it and if you want to become that images by code on your view, you can see in my next article. Then, expect for that and stay tuned.
Information technology tin accept few moments to download the image is in progress.
Hither'south the concluding output and y'all tin can see my image:
Thank you for reading this article and await for next,
Connect("Nitin Pandit");
Source: https://www.c-sharpcorner.com/UploadFile/8ef97c/upload-image-to-azure-blob-storage-in-Asp-Net-part-2/
0 Response to "upload image to azure blob storage c# ms crm plugin"
Post a Comment