Raghvendr Singh

Raghvendr Singh

  • NA
  • 117
  • 127.8k

File upload/download

Jan 12 2011 1:51 AM

I have written code for file upload / download .It is working fine but when using download manager(DAP) then instead of file ,.aspx  file is being download itself.
please suggest me.
For uploading I used code as:
//fupload is asp:FileUpload control
fupload.SaveAs(Server.MapPath(
"./Image1/Image1/"+fupload.FileName));
and for downloading :
//fName is string that holds file name for downloading
System.IO.
FileInfo fileToDownload = new System.IO.FileInfo(Server.MapPath("Image1/Image1/"+fName));
if
(fileToDownload.Exists)
{
Response.Clear();
Response.AddHeader(
"Content-Disposition", "attachment; filename=" + fileToDownload.Name);
//Response.AddHeader("Content-Length", fileToDownload.Length.ToString());
Response.ContentType =
"application/OCTET-STREAM";
//Response.Flush();
Response.WriteFile(fileToDownload.FullName);
Response.End();
}

Answers (1)