private string GetFilePath(Entity.File file) { var path = BuildFilePath(file); var config = mConfigProvider.GetConfig(); return(Path.Combine(config.RootPath, path)); }
public Task <Entity.File> WriteFileAsync(Entity.File file, byte[] content, CancellationToken?token = null) { var path = GetFilePath(file); System.IO.Directory.CreateDirectory(Path.GetDirectoryName(path)); System.IO.File.WriteAllBytes(path, content); return(Task.FromResult(file)); }
public Task <Entity.File> DeleteFileAsync(Entity.File file, CancellationToken?token = null) { if (file != null) { var path = GetFilePath(file); System.IO.File.Delete(path); } return(Task.FromResult(file)); }
public async Task <Entity.File> WriteFileAsync(Entity.File file, Stream stream, CancellationToken?token = null) { var path = GetFilePath(file); System.IO.Directory.CreateDirectory(Path.GetDirectoryName(path)); using (var fileStream = System.IO.File.OpenWrite(path)) { await stream.CopyToAsync(fileStream, token ?? CancellationToken.None); } return(file); }
public Task <Stream> ReadFileAsync(Entity.File file, CancellationToken?token = null) { var path = GetFilePath(file); Stream stream = null; if (File.Exists(path)) { stream = System.IO.File.OpenRead(path); } return(Task.FromResult(stream)); }
private string BuildFilePath(Entity.File file) { var year = file.CreatedDate.Year.ToString(); var monthNumb = file.CreatedDate.Month.ToString(); var monthName = file.CreatedDate.ToString("MMM", CultureInfo.InvariantCulture); var day = file.CreatedDate.Day.ToString(); var fileExt = Path.GetExtension(file.Name); //var fileName = Guid.NewGuid().ToString(); var fileName = file.Id.ToString(); var relativeFilePath = Path.Combine(year, $"{monthNumb:00}_{monthName}", day, $"{fileName}{fileExt}"); return(relativeFilePath); }
public ActionResult Upload(HttpPostedFileBase upload) { string fileName = upload.FileName; string userName = this.User.Identity.Name; var userManager = HttpContext.GetOwinContext().GetUserManager <AppUserManager>(); var user = userManager.FindByName(userName); var file = new Entity.File() { FileName = fileName, UserId = user.Id }; context.Files.Add(file); context.SaveChanges(); SaveFile(upload, file.FileId.ToString()); return(RedirectToAction("FileUsers")); }
public Task <Stream> ReadFileAsync(Entity.File file, CancellationToken?token = null) { throw new System.NotImplementedException(); }
public Task <Entity.File> WriteFileAsync(Entity.File file, Stream stream, CancellationToken?token = null) { throw new System.NotImplementedException(); }