downloading files from filesystem

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
 
N

nahid

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top