File download problem
ASP.NET
1
Posts
1
Posters
0
Views
1
Watching
-
hi all, i have a page that enables site user to download report files from the server. report file types are .pdf, .doc, .ppt and .xls for that what i am doing is creating a Stream from file and convert it into the byte and binary write the output... so it is working fine in IE but while using netscape, the download dialog concat the file name with .aspx ( fileName.pdf.aspx ), so netscape can not open the file with proper application.. any solution please help me, thanks in advance here i m giving my code for depth review the problem
if ( File.Exists( sPathName ) ) { using( FileStream oFStream = new FileStream( sPathName, FileMode.Open ) ) { iFileLength = (int)oFStream.Length; buffer = new byte[iFileLength]; oFStream.Read( buffer, 0, iFileLength ); oFStream.Close(); } Response.Buffer = true; Response.Clear(); Response.ContentType = "application/" + Path.GetExtension( sPathName ).Remove(0, 1); Response.AddHeader( "Content-Type", "application/octet-stream" ); Response.AddHeader( "Content-Length", iFileLength.ToString() ); Response.AddHeader( "Content-Disposition", "attachment; filename=\"" + Path.GetFileName( sPathName ) + "\"; Size=" + iFileLength.ToString()); Response.BinaryWrite( buffer ); Response.Flush(); }
Confidence comes not from always being right, but from not fearing to be wrong..... Mihir..