public AttachFileTransferData UploadFileAndSave(HttpPostedFileBase file, string newName)
        {
            if (file.ContentLength > 0)
            {
                if (SilentDeleteFileIsExists)
                {
                    DeleteFile(newName);
                }
                else
                {
                    if (FileExists(newName))
                    {
                        throw new FileLoadException("File with current name is exists");
                    }
                }

                string fileName     = Path.GetFileName(file.FileName);
                string fileFullName = Path.Combine(Server.MapPath("~/App_Data/uploads/temp"), fileName);
                file.SaveAs(fileFullName);

                string newFullName = Path.Combine(Server.MapPath("~/App_Data/uploads/data"), newName);
                System.IO.File.Move(fileFullName, newFullName);

                AttachFileTransferData data = new AttachFileTransferData();
                data.guid      = newName;
                data.Name      = Path.GetFileNameWithoutExtension(fileName);
                data.Extension = Path.GetExtension(fileName);
                return(data);
            }
            return(null);
        }
Beispiel #2
0
        public ActionResult UploadFile()
        {
            List <AttachFileTransferData> data = new List <AttachFileTransferData>();

            for (int n = 0; n < Request.Files.Count; n++)
            {
                AttachFileTransferData atd = controllerUtils.UploadFileAndSave(Request.Files[n]);
                if (atd != null)
                {
                    data.Add(atd);
                }
            }
            return(Json(data));
        }