downloading files from filesystem

  • Thread starter Thread starter Tina
  • Start date Start date
T

Tina

My app needs to provide download of files (in this case .doc files) that
exist on the file system. I have the physical filestring i.e.
c:\myfilesdir\smith resume.doc.
but if I load that into a navigateurl it doesn't work. Nor does
file://c:\myfilesdir\smith resume.doc. Or any thing else I try.

How can I do this?

Thanks,
T
 
My app needs to provide download of files (in this case .doc files) that
exist on the file system. I have the physical filestring i.e.
c:\myfilesdir\smith resume.doc.
but if I load that into a navigateurl it doesn't work. Nor does
file://c:\myfilesdir\smith resume.doc. Or any thing else I try.

How can I do this?

Thanks,
T

hi,
try this way
String file = Server.MapPath("~/labla/") +
"labla....";
string fileName = "ClientFileName";

try
{
FileStream downloadFile = new FileStream(file,
FileMode.Open);

Response.Clear();

Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition",
"attachment; filename=\"" + fileName + "\"");
Response.AddHeader("Content-Length",
downloadFile.Length.ToString());

downloadFile.Close();

Response.WriteFile(file);

Response.Flush();
}
catch (Exception ex)
{
//...............

}

hope help
nahid
http://nahidulkibria.blogspot.com
 
Back
Top