public ActionResult Upload(HttpPostedFileBase file) { string filename = Path.GetFileName(file.FileName); LostDocFileInfo fileInfo; using (TempDir tempDir = new TempDir()) { string tempLocation = Path.Combine(tempDir.Path, filename); file.SaveAs(tempLocation); fileInfo = new LostDocFileInfo(tempLocation); string targetFile = string.Format("{0}_{1}.ldoc", fileInfo.PrimaryAssembly.Filename, fileInfo.PrimaryAssembly.AssetId.Version); if (System.IO.File.Exists(Path.Combine(AppConfig.RepositoryPath, targetFile))) { string message = string.Format("Unable to add file '{0}' as it already exists.", targetFile); App.Instance.Notifications.Add(Severity.Error, Lifetime.Page, Scope.User, this.User, "Failed to upload file", message); } else { System.IO.File.Move(tempLocation, Path.Combine(AppConfig.RepositoryPath, targetFile)); string message = string.Format("Successfully added file '{0}' (as '{1}') to repository.", filename, targetFile); App.Instance.Notifications.Add( Severity.Information, Lifetime.Page, Scope.User, this.User, "File uploaded", message); } } return(this.RedirectToAction("Index")); }
public ActionResult Upload(HttpPostedFileBase file) { string filename = Path.GetFileName(file.FileName); LostDocFileInfo fileInfo; using (TempDir tempDir = new TempDir(AppConfig.TempPath)) { string tempLocation = Path.Combine(tempDir.Path, filename); file.SaveAs(tempLocation); fileInfo = new LostDocFileInfo(tempLocation); string targetFile = string.Format("{0}_{1}.ldoc", fileInfo.PrimaryAssembly.Filename, fileInfo.PrimaryAssembly.AssetId.Version); if (System.IO.File.Exists(Path.Combine(AppConfig.RepositoryPath, targetFile))) { string message = string.Format("Unable to add file '{0}' as it already exists.", targetFile); this.Notifications.Add(Severity.Error, Lifetime.Page, Scope.User, this.User, "Failed to upload file", message); } else { System.IO.File.Move(tempLocation, Path.Combine(AppConfig.RepositoryPath, targetFile)); string message = string.Format("Successfully added file '{0}' (as '{1}') to repository.", filename, targetFile); this.Notifications.Add( Severity.Information, Lifetime.Page, Scope.User, this.User, "File uploaded", message); } } return this.RedirectToAction("Index"); }