downloading a large file using asp.net 2.0 with C#
-
hai my code: Response.Clear(); Response.AppendHeader("Content-Disposition","attachment; filename=" + filename); Response.AppendHeader("Content-Length", filename.Length.ToString()); Response.ContentType = "text/plain"; //if pdf file "application/pdf" string strMapPath = Server.MapPath("~FolderName/filename); FileStream fs = new FileStream(strMapPath, FileMode.Open,FileAccess.Read, FileShare.ReadWrite); long bytesToGo; int bytesRead; Byte[] buffer = new byte[1048576]; bytesToGo = fs.Length; while (bytesToGo > 0) { bytesRead = fs.Read(buffer, 0, 1048576); Response.OutputStream.Write(buffer, 0, bytesRead); Response.Flush(); bytesToGo -= bytesRead; } fs.Close(); Response.End(); my problem is downloaded file .sql file[size:4mb], which was not fully downloaded, it partially downloaded.i.e the download file doesn't show the full content it shows only 10 or 15 lines. if anyone known about this,help me Thanks in Advance
Known is a drop , Unknown is an Ocean
-
hai my code: Response.Clear(); Response.AppendHeader("Content-Disposition","attachment; filename=" + filename); Response.AppendHeader("Content-Length", filename.Length.ToString()); Response.ContentType = "text/plain"; //if pdf file "application/pdf" string strMapPath = Server.MapPath("~FolderName/filename); FileStream fs = new FileStream(strMapPath, FileMode.Open,FileAccess.Read, FileShare.ReadWrite); long bytesToGo; int bytesRead; Byte[] buffer = new byte[1048576]; bytesToGo = fs.Length; while (bytesToGo > 0) { bytesRead = fs.Read(buffer, 0, 1048576); Response.OutputStream.Write(buffer, 0, bytesRead); Response.Flush(); bytesToGo -= bytesRead; } fs.Close(); Response.End(); my problem is downloaded file .sql file[size:4mb], which was not fully downloaded, it partially downloaded.i.e the download file doesn't show the full content it shows only 10 or 15 lines. if anyone known about this,help me Thanks in Advance
Known is a drop , Unknown is an Ocean
Can you explain a bit more your problem, what do you mean by
ganeshMohan wrote:
my problem is downloaded file .sql file[size:4mb], which was not fully downloaded, it partially downloaded.i.e the download file doesn't show the full content it shows only 10 or 15 lines.
Whats the code above for, is it from the downloaded file? Where are you downloading the file from?
-
hai my code: Response.Clear(); Response.AppendHeader("Content-Disposition","attachment; filename=" + filename); Response.AppendHeader("Content-Length", filename.Length.ToString()); Response.ContentType = "text/plain"; //if pdf file "application/pdf" string strMapPath = Server.MapPath("~FolderName/filename); FileStream fs = new FileStream(strMapPath, FileMode.Open,FileAccess.Read, FileShare.ReadWrite); long bytesToGo; int bytesRead; Byte[] buffer = new byte[1048576]; bytesToGo = fs.Length; while (bytesToGo > 0) { bytesRead = fs.Read(buffer, 0, 1048576); Response.OutputStream.Write(buffer, 0, bytesRead); Response.Flush(); bytesToGo -= bytesRead; } fs.Close(); Response.End(); my problem is downloaded file .sql file[size:4mb], which was not fully downloaded, it partially downloaded.i.e the download file doesn't show the full content it shows only 10 or 15 lines. if anyone known about this,help me Thanks in Advance
Known is a drop , Unknown is an Ocean
Try
Response.WriteFile
orResponse.TransmitFile
.Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson -
hai my code: Response.Clear(); Response.AppendHeader("Content-Disposition","attachment; filename=" + filename); Response.AppendHeader("Content-Length", filename.Length.ToString()); Response.ContentType = "text/plain"; //if pdf file "application/pdf" string strMapPath = Server.MapPath("~FolderName/filename); FileStream fs = new FileStream(strMapPath, FileMode.Open,FileAccess.Read, FileShare.ReadWrite); long bytesToGo; int bytesRead; Byte[] buffer = new byte[1048576]; bytesToGo = fs.Length; while (bytesToGo > 0) { bytesRead = fs.Read(buffer, 0, 1048576); Response.OutputStream.Write(buffer, 0, bytesRead); Response.Flush(); bytesToGo -= bytesRead; } fs.Close(); Response.End(); my problem is downloaded file .sql file[size:4mb], which was not fully downloaded, it partially downloaded.i.e the download file doesn't show the full content it shows only 10 or 15 lines. if anyone known about this,help me Thanks in Advance
Known is a drop , Unknown is an Ocean