Simple Download PDF/Excel Code In Asp Dot

Simple Download PDF/Excel Code In Asp Dot

 if (e.CommandName == "Download")
                {
                    StringBuilder sb = new StringBuilder();
                    string DocumentName = e.CommandArgument.ToString();
                    if (DocumentName != null)
                    {
                        string FolderName = Server.MapPath("~").Replace("\\", "/") +   "ConManagement/Documents";
                        sb.Clear();
                        sb.Append(FolderName);
                        sb.Append("/");
                        sb.Append(DocumentName.ToString());
                        string FileName = sb.ToString();
                        sb.Clear();

                        if (FileName != string.Empty)
                        {
                            Response.Clear();
                            Response.ContentType = "application/pdf/xlsx/doc";
                            Response.AppendHeader("Content-Disposition", "attachment; filename= " + DocumentName.ToString());
                            Response.TransmitFile(FileName);
                            Response.End();
                        }
                    }
                }

Comments

Popular posts from this blog

String Program in C#

CSV using XmlNode

Controller_Model. cs