hi
Many web applications provide the download option.i want to known about how work in data server.
How to Download files from Database sever in VB.NET
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Scott LysleRank #49 · 31K reputationPosted May 15, 2011, 11:57 PM EDT
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();
}