private void DownloadTemplate(string FileName) { try { String strFile = String.Empty; String[] filename; strFile = Server.MapPath(ConfigurationManager.AppSettings["TemplatePath"].ToString()) + FileName; filename = strFile.Split('\\'); Response.Clear(); Response.Buffer = true;// Read the original file from diskFileStream * Response.AddHeader("Content-Disposition", "attachment; filename=" + filename[filename.Length-1]); String ext = String.Empty; if (strFile.IndexOf(".") > 0) ext = (strFile.Split('.'))[1]; if (ext.ToLower() == "txt") Response.ContentType = "text/html"; if (ext.ToLower() == "xls") Response.ContentType = "xls/html"; if (ext.ToLower() == "pdf") Response.ContentType = "application/pdf"; ////combine the path and file name if (File.Exists(strFile))//open the file and process it { FileStream sourceFile = new FileStream(strFile, FileMode.Open, FileAccess.Read); long FileSize; FileSize = sourceFile.Length; Response.AddHeader("Content-Length", FileSize.ToString()); //* byte[] getContent = new byte[(int)FileSize]; sourceFile.Read(getContent, 0, (int)FileSize); sourceFile.Close(); Response.BinaryWrite(getContent); } Common.UserPageAudit(Session["User"].ToString(), "Download Templates", Session["ROLE"].ToString(), strFile + " Template downloaded"); } catch (Exception ex) { Response.Redirect("../CustomError.aspx?Err=" + ex.Message.ToString(), false); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)