public FileViewModel GetFile(ListItem file) { var path = Path.Combine(ConfigurationHelper.GetTemporaryFilesFolder(), file.Id, file.Value); if (File.Exists(path)) { FileStream fsSource = null; try { fsSource = new FileStream(path, FileMode.Open, FileAccess.Read); var viewModel = new FileViewModel { FileName = file.Value, InputStream = fsSource }; return viewModel; } catch (Exception ex) { if (fsSource != null) { fsSource.Dispose(); } throw; } } return null; }
public ListItem SaveAttachmentToTempFolder(FileViewModel fileViewModel) { var folderName = Guid.NewGuid().ToString(); var path = Path.Combine(ConfigurationHelper.GetTemporaryFilesFolder(), folderName); Directory.CreateDirectory(path); using (var file = File.Create(Path.Combine(path, fileViewModel.FileName))) { fileViewModel.InputStream.CopyTo(file); } return new ListItem() { Value = fileViewModel.FileName, Id = folderName }; }