I have the following code which uploads files to the local host then allows user to download the file. This code workes perfectly however what I now want to be able to do is link this to my azure storage account. if a file is uploaded to this website I want
it to auto upload to azure. How would I go about altering this code any help is appreciated. Thanks
Note my data source is a table in Microsoft sql.
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub btnAddNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddNew.Click
Response.Redirect("~/UploadFile.aspx")
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Select Case (e.Row.RowType)
Case DataControlRowType.DataRow
Dim myFileInfo As FileInfo = CType(e.Row.DataItem, FileInfo)
Select Case myFileInfo.ContentType.ToLower()
Case "image/pjpeg" ' .jpg files
Case "image/gif" ' .gif files
Case "application/msword" ' .doc files
Case "text/plain" ' .txt files
' Do nothing. When the row contains a viewable type,
' we want the View link to be enabled.
Case Else
' Find the View link and disable it.
Dim myLink As HyperLink = CType(e.Row.FindControl("lnkView"), HyperLink)
myLink.Enabled = False
End Select
End Select
End Sub
End Class
Assuming that you already have a Blob Storage Container configured in Azure (with the appropriate connection string), then you can just use a BlobServiceClient to handle uploading your file as a stream to your container:
// Create a BlobServiceClient object which will be used to create a container client
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
// Read your file (after casting from your example)
var file = e.Row.DataItem as FileInfo;
using(FileStream stream = file.OpenRead())
{
// Upload your file
blobServiceClient.UploadAsync(stream);
}
Member
51 Points
180 Posts
upload / dowload files to azure
Jan 15, 2020 09:49 AM|E.RU|LINK
I have the following code which uploads files to the local host then allows user to download the file. This code workes perfectly however what I now want to be able to do is link this to my azure storage account. if a file is uploaded to this website I want it to auto upload to azure. How would I go about altering this code any help is appreciated. Thanks
Note my data source is a table in Microsoft sql.
All-Star
114593 Points
18503 Posts
MVP
Re: upload / dowload files to azure
Jan 16, 2020 02:13 AM|Rion Williams|LINK
Assuming that you already have a Blob Storage Container configured in Azure (with the appropriate connection string), then you can just use a BlobServiceClient to handle uploading your file as a stream to your container:
You can find a complete tutorial to handle this here, but hopefully this should get the basic idea. Additionally, if you need to convert between C# and Visual Basic (as most examples will be in C#), you can use this converter here.