Monday, August 18, 2008

Downloading file from a URL/Open Save dialog in downloading file

Some time you need to download the file from the URL then follwing code can help u out.


private void downloadURL(string fileURL)
{

//::->STEP
//::->Step -1 :::->Get filename
//::->Step -2 :::->Adding Headeres
//::->Step -3 :::->Set the Content Type
//::->Step -4 :::->Tansmit the file
//::->Step -5 :::->End of the Response

string name = Path.GetFileName(fileURL);

// ::->Get filename
string fileName = Path.GetFileName(fileURL);

// ::-> Adding Headeres
Response.AddHeader("Content-disposition", "attachment; filename=" + fileName);

//::-> Set the Content Type
Response.ContentType = "application/octet-stream";

//::-> Tansmit the file
Response.TransmitFile(fileURL);

//::-> End of the Response
Response.End();

}