public void ProcessRequest(HttpContext context) { using (CuteWebUI.MvcUploader uploader = new CuteWebUI.MvcUploader(context)) { uploader.UploadUrl = context.Response.ApplyAppPathModifier(VirtualPathUtility.ToAbsolute("~/UploadHandlerDocument.ashx")); //the data of the uploader will render as <input type='hidden' name='myuploader'> uploader.Name = "myuploader"; uploader.AllowedFileExtensions = Cotecna.Vestalis.Web.Properties.Settings.Default.ExtensionDocumentAllowed; //let uploader process the common task and return common result uploader.PreProcessRequest(); //if need validate the file : (after the PreProcessRequest have validated the size/extensions) if (uploader.IsValidationRequest) { //get the file need be validated: uploader.WriteValidationOK(); return; } else { uploader.WriteValidationError(Resources.Common.FileTypeIsNotAuthorized); } } }
public PartialViewResult Attachment(string myuploader) { using (CuteWebUI.MvcUploader uploader = new CuteWebUI.MvcUploader(System.Web.HttpContext.Current)) { uploader.UploadUrl = Response.ApplyAppPathModifier("~/UploadHandler.ashx"); //the data of the uploader will render as <input type='hidden' name='myuploader'> uploader.Name = "myuploader"; uploader.AllowedFileExtensions = "*.jpg,*.gif,*.png,*.bmp,*.doc,*.docx"; //allow select multiple files uploader.MultipleFilesUpload = true; uploader.ManualStartUpload = true; //tell uploader attach a button uploader.InsertButtonID = "uploadbutton"; //prepair html code for the view ViewData["uploaderhtml"] = uploader.Render(); string Path = Server.MapPath("~/Images/Guest/"); //if it's HTTP POST: if (!string.IsNullOrEmpty(myuploader)) { List<string> processedfiles = new List<string>(); //for multiple files , the value is string : guid/guid/guid foreach (string strguid in myuploader.Split('/')) { Guid fileguid = new Guid(strguid); CuteWebUI.MvcUploadFile file = uploader.GetUploadedFile(fileguid); if (file != null) { //you should validate it here: //now the file is in temporary directory, you need move it to target location //file.MoveTo("~/myfolder/" + file.FileName); System.IO.FileInfo F = new System.IO.FileInfo(Server.MapPath("~/Images/Guest/" + file.FileName.ToString())); { if (F.Exists) { F.IsReadOnly = false; F.Delete(); } } file.MoveTo(Path + file.FileName); processedfiles.Add(file.FileName); } } if (processedfiles.Count > 0) { ViewData["UploadedMessage"] = string.Join(",", processedfiles.ToArray()) + " have been processed."; } } } return PartialView(); }
public ActionResult LoadAddItem(int CourseItemID, int CourseID, string SystemObjectName, string IsCourseHomePage) { GenericBE objGenericModel = new GenericBE(); int SystemObjectID = (int)Enum.Parse(typeof(SystemObject), SystemObjectName); if (CourseItemID <= 0) { // load default answer new answer //objGenericModel.ParentCourseItemID = ParentCID; objGenericModel.CourseID = CourseID; objGenericModel.SystemObjectName = SystemObjectName; objGenericModel.CourseID = CourseID; objGenericModel.IsAddItem = true; objGenericModel.IsCourseHomePage = Convert.ToInt32(IsCourseHomePage); //return View(objGenericModel); } else if (CourseItemID > 0) { // Call Database and get value long AccountID; CourseItem objCourseItem = new CourseItem(); if (Request.Cookies["ID"] != null) { AccountID = Convert.ToInt64(Request.Cookies["ID"].Value.ToString()); objGenericModel = objCourseItem.CourseItemDetails(AccountID, SystemObjectID, CourseItemID).Single(); } objGenericModel.IsAddItem = false; objGenericModel.IsCourseHomePage = Convert.ToInt32(IsCourseHomePage); } using (CuteWebUI.MvcUploader uploader = new CuteWebUI.MvcUploader(System.Web.HttpContext.Current)) { uploader.UploadUrl = Response.ApplyAppPathModifier("~/UploadHandler.ashx"); //the data of the uploader will render as <input type='hidden' name='myuploader'> uploader.Name = "myuploader"; uploader.AllowedFileExtensions = "*.jpg,*.gif,*.png,*.bmp,*.doc,*.docx,*.pdf,*.xls,*.xlsx,*.ppt,*.ppsx"; //allow select multiple files uploader.MultipleFilesUpload = true; uploader.ManualStartUpload = true; //tell uploader attach a button uploader.InsertButtonID = "uploadbutton"; //prepair html code for the view ViewData["uploaderhtml"] = uploader.Render(); } return View(objGenericModel); }