public IActionResult Upload(IList <IFormFile> files) { foreach (var file in files) { ContentDispositionHeaderValue header = ContentDispositionHeaderValue.Parse(file.ContentDisposition); string fileName = header.FileName; fileName = fileName.Trim('"'); fileName = Path.GetFileName(fileName); MemoryStream ms = new MemoryStream(); Stream s = file.OpenReadStream(); s.CopyTo(ms); byte[] data = ms.ToArray(); s.Dispose(); ms.Dispose(); UploadedFile primaryObj = new UploadedFile(); primaryObj.FileName = fileName; primaryObj.ContentType = file.ContentType; primaryObj.Size = file.Length; primaryObj.TimeStamp = DateTime.Now; primaryObj.FileContent = data; IUploadedFile backupObj = primaryObj.Clone(); //IUploadedFile backupObj = primaryObj.DeepCopy(); //send primaryObj to main system //send backupObj to backup system } ViewBag.Message = files.Count + " file(s) uploaded successfully!"; return(View("Index")); }
public ActionResult Prototype() { IUploadedFile u = new UploadedFile(); u.Clone(); u.DeepCopy(); return(View()); }
// Редактирование записи о файле в таблице файлов public static void EditFileRecord(DataGridView table, ICollection <UploadedFile> deletingFilesList) { UploadedFile selectedFile = table.SelectedRows[0].DataBoundItem as UploadedFile; UploadedFile selectedFileCopy = selectedFile.Clone() as UploadedFile; AddEditFileForm ef = new AddEditFileForm(selectedFile); ef.ShowDialog(); // Если заменён файл - помещаем старый файл в список на удаление if (FileManager.WasFileUploaded(selectedFileCopy) && (!selectedFileCopy.PhisicalName.Equals(ef.CreatedFile.PhisicalName))) { deletingFilesList.Add(new UploadedFile { PhisicalName = selectedFileCopy.PhisicalName }); } table.Refresh(); }