if (FileUpload1.HasFile) { if (FileUpload1.PostedFile.ContentLength / 1024 > 2048) throw new ApplicationException ("Uploaded File Should less then 2MB"); filename = FileUpload1.PostedFile.FileName; FileUpload1.SaveAs(Server.MapPath ("~/FILE_UPLOADS/ARREST_MEMO/ ") + (filename)); Regex FilenameRegex; FilenameRegex = new Regex("(.*?)\\.(pdf)$", RegexOptions.IgnoreCase); if (!FilenameRegex.IsMatch(filename)) throw new ApplicationException("Browse PDF files Only"); }
try { filename = UpName.Value.ToString(); filepath = type = System.IO.Path.GetExtension(filename); Byte[] bytes = Convert.FromBase64String(UpData.Value); //Response.Clear(); //Response.ClearHeaders(); Response.Buffer = true; Response.Charset = ""; this.EnableViewState = false; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "Application/pdf"; //Response.AddHeader("Content-Disposition", "attachment;filename=" + filename); Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filepath)); Response.TransmitFile(Server.MapPath(filepath)); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); HttpContext.Current.ApplicationInstance.CompleteRequest(); }
PostedFile.FileName
FileName
Path.GetInvalidFileNameChars
exe
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)