Download a file from db
-
hi all, I want to download the file from db which has been save in my application.I downloaded the file . but i want to open it as a pdf file.How to do that.. Here is the code i used to download.
if (e.CommandName == "ResumeDownload") { Cache\["filename"\] = e.CommandArgument.ToString(); String strRequest = Cache\["filename"\].ToString();// '-- if something was passed to the file querystring if (strRequest != "") // 'get absolute path of the file { String path = Server.MapPath("Attachments\\\\" + strRequest);// 'get file object as FileInfo FileInfo file = new FileInfo(path);// '-- if the file exists on the server if (file.Exists) { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=\\"" + file.Name.ToString()+ "\\""); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.WriteFile(file.FullName); Response.End();// 'if file does not exist } else ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script>alert('File Not Found')</script>"); } else Response.Write("Please provide a file to download."); }
-
hi all, I want to download the file from db which has been save in my application.I downloaded the file . but i want to open it as a pdf file.How to do that.. Here is the code i used to download.
if (e.CommandName == "ResumeDownload") { Cache\["filename"\] = e.CommandArgument.ToString(); String strRequest = Cache\["filename"\].ToString();// '-- if something was passed to the file querystring if (strRequest != "") // 'get absolute path of the file { String path = Server.MapPath("Attachments\\\\" + strRequest);// 'get file object as FileInfo FileInfo file = new FileInfo(path);// '-- if the file exists on the server if (file.Exists) { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=\\"" + file.Name.ToString()+ "\\""); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.WriteFile(file.FullName); Response.End();// 'if file does not exist } else ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script>alert('File Not Found')</script>"); } else Response.Write("Please provide a file to download."); }
Try changing the ContentType to application/pdf. I haven't tried this so there is every chance it won't work but you never know.
-
Try changing the ContentType to application/pdf. I haven't tried this so there is every chance it won't work but you never know.
-
Try changing the ContentType to application/pdf. I haven't tried this so there is every chance it won't work but you never know.
DoctorMick wrote:
application/pdf
this wont work.. This will open a pdf but without any content.....
Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]