[AcceptVerbs("Post")]
public void Save()
{
try
{
if (System.Web.HttpContext.Current.Request.Files.AllKeys.Length > 0)
{
var httpPostedFile = System.Web.HttpContext.Current.Request.Files["UploadFiles"];
if (httpPostedFile != null)
{
var fileSave = System.Web.HttpContext.Current.Server.MapPath("UploadedFiles");
var fileSavePath = Path.Combine(fileSave, httpPostedFile.FileName);
if (!System.IO.File.Exists(fileSavePath))
{
httpPostedFile.SaveAs(fileSavePath); // the file is saved here
HttpResponse Response = System.Web.HttpContext.Current.Response;
Response.Clear();
Response.ContentType = "application/json; charset=utf-8";
Response.StatusDescription = "File uploaded succesfully";
Response.End();
}
else
{
HttpResponse Response = System.Web.HttpContext.Current.Response;
Response.Clear();
Response.Status = "204 File already exists";
Response.StatusCode = 204;
Response.StatusDescription = "File already exists";
Response.End();
}
}
}
}
catch (Exception e)
{
HttpResponse Response = System.Web.HttpContext.Current.Response;
Response.Clear();
Response.ContentType = "application/json; charset=utf-8";
Response.StatusCode = 204;
Response.Status = "204 No Content";
Response.StatusDescription = e.Message;
Response.End();
}
} |
public ActionResult Index()
{
UploadFileModel fileModel = new UploadFileModel();
fileModel.Files.Add(new UploaderUploadedFiles { Name = "Nature", Size = 500000, Type = ".png" });
fileModel.Files.Add(new UploaderUploadedFiles { Name = "TypeScript Succinctly", Size = 12000, Type = ".pdf" });
fileModel.Files.Add(new UploaderUploadedFiles { Name = "ASP.NET Webhooks", Size = 500000, Type = ".docx" });
return View(fileModel);
}
public class UploadFileModel
{
public UploadFileModel()
{
Files = new List<UploaderUploadedFiles>();
}
public List<UploaderUploadedFiles> Files { get; set; }
} |
@Html.EJS().Uploader("UploadFiles").DropArea(".control-fluid").MinFileSize(10000).Removing("onFileRemove").MaxFileSize(4000000).AsyncSettings(new Syncfusion.EJ2.Inputs.UploaderAsyncSettings { SaveUrl = @Url.Content("~/Uploader/Save"), RemoveUrl = @Url.Content("~/Uploader/Remove") }).Files(files =>
{
foreach (var f in Model?.Files)
{
files.Name(f.Name).Size(f.Size).Type(f.Type).Add();
}
}) |