//below is the aspx code for uploading files. //Add reference for ajax file upload library.
//Create Handler to save file and write below code inside Process Request public void ProcessRequest (HttpContext context) { try { string Attachment = ""; string attachmentPath = ""; context.Response.ContentType = "text/plain"; context.Response.Expires = -1; string pathToSave = context.Server.MapPath(@"~\FolderPath\"); string fileName = string.Empty; string fextention = string.Empty; foreach (string f in context.Request.Files.AllKeys) { HttpPostedFile file = context.Request.Files[f]; if (!String.IsNullOrEmpty(file.FileName)) { Attachment = file.FileName; Attachment = Attachment.Replace(" ", ""); Attachment = Attachment.Replace("'", ""); Attachment = pathToSave + Attachment; file.SaveAs(Attachment); } } } catch (Exception ex) { context.Response.Write("Error: " + ex.Message); } }
No comments:
Post a Comment