Monday, September 6, 2010

VB.NET Upload & Download a file

// UPLOAD
//drag fileupload control for path and a button for upload

Dim file As String
file = Path.GetFileName(FileUpload1.FileName)
FileUpload1.SaveAs("C:\Inetpub\wwwroot\order\images\" + file)
//it is better to save file in another folde rather than the inetpub JUST LIKE BELOW
FileUpload1.SaveAs("d:\kapil\images\" + file)
lblupload.Text = "File Upload Complete...."
labelsize.text=FileUpload1.PostedFile.ContentLength

//DOWNLOAD

Response.AppendHeader("Content-Disposition", "attachment; filename=ecc1.jpg")
Response.TransmitFile(Server.MapPath("~/images/ecc1.jpg"))
//Response.TransmitFile("d:/kapil/images/ecc1.jpg")
Response.End()

//By Default, maximum allowed size for file is 4MB. To allow files larger than the default of 4MB, one need to change the web.config file(in system.web TAB).There is a parameter called maxRequestLength which takes value in the KB.
 


//1048576 is around 1GB

No comments: