hi
Many web applications provide the download option.i want to known about how work in data server.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Scott LyslePosted May 16, 2011, 3:57 AM
If the file were just stored in a folder, you could use something as simple as this:
protected void LinkButton1_Click(object sender, EventArgs e)
{
DownloadFile("c:\\temp\\somefiletodownload.docx");
}
protected void DownloadFile(string sFile)
{
string file = sFile;
UriBuilder uBuild = new UriBuilder();
System.Net.WebRequest wReq = System.Net.WebRequest.Create(file);
System.Net.WebResponse wResponse = (System.Net.WebResponse)wReq.GetResponse();
Response.AppendHeader("Content-Disposition", "attachment;filename=" + file);
Response.ContentType = wResponse.ContentType;
Stream fStream = wResponse.GetResponseStream();
byte[] buff = new byte[4096];
Response.Clear();
int bytes;
while ((bytes = fStream.Read(buff, 0, buff.Length)) > 0)
{
Response.OutputStream.Write(buff, 0, bytes);
}
fStream.Close();
wResponse.Close();
Response.Flush();
Response.End();
}