public void CreateFolderAndDeleteFolderTakesAnySlash() { Assert.Equal(_storageProvider.ListFolders(@"Subfolder1").Count(), 1); _storageProvider.CreateFolder(@"SubFolder1/SubSubFolder2"); _storageProvider.CreateFolder(@"SubFolder1\SubSubFolder3"); Assert.Equal(_storageProvider.ListFolders(@"Subfolder1").Count(), 3); _storageProvider.DeleteFolder(@"SubFolder1/SubSubFolder2"); _storageProvider.DeleteFolder(@"SubFolder1\SubSubFolder3"); Assert.Equal(_storageProvider.ListFolders(@"Subfolder1").Count(), 1); }
/// <summary> /// Creates a media folder. /// </summary> /// <param name="relativePath">The path where to create the new folder. null means root.</param> /// <param name="folderName">The name of the folder to be created.</param> public MediaFolder CreateFolder(string relativePath, string folderName) { ArgumentHelper.ThrowIfNullOrEmpty(folderName, "folderName"); var folder = storageProvider.CreateFolder(relativePath == null ? folderName : storageProvider.Combine(relativePath, folderName)); return(BuildMediaFolder(folder)); }
public static void AnyFolders(IStorageProvider provider) { if (provider.IsFolderExits("container\\TestFolder\\TestFolder")) { provider.DeleteFolder("container\\TestFolder\\TestFolder"); } provider.CreateFolder("container\\TestFolder\\TestFolder"); Assert.IsTrue(provider.ListFolders("container\\TestFolder\\").Any()); provider.DeleteFolder("container\\TestFolder\\TestFolder"); }
public FileResult Upload(HttpPostedFileBase file, string directoryName, string fileName) { string path = storage.GetStoragePath(directoryName); var extension = Path.GetExtension(fileName); var fullPath = Path.Combine(path, fileName); storage.CreateFolder(path); file.SaveAs(fullPath); return(new FileResult(fileName, path, storage.GetPublicUrl(Path.Combine(directoryName, fileName)), file.ContentType, extension)); }
public static void SuccessCreateFolder(IStorageProvider provider) { if (provider.IsFolderExits("container\\TestFolder")) { provider.DeleteFolder("container\\TestFolder"); } provider.CreateFolder("container\\TestFolder"); Assert.IsTrue(provider.IsFolderExits("container\\TestFolder")); provider.DeleteFolder("container\\TestFolder"); Assert.IsFalse(provider.IsFolderExits("container\\TestFolder")); }
private string DownloadFile(string source, Uri uri, string folderPath, bool isSingleFile = false) { var destinationFolder = folderPath; var currentUri = new Uri(uri, source); if (!isSingleFile) { var folderSegments = currentUri.LocalPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); for (var i = 0; i < folderSegments.Length - 1; i++) { destinationFolder = _storageProvider.Combine(destinationFolder, folderSegments[i]); } } if (!_storageProvider.FolderExists(destinationFolder)) { _storageProvider.CreateFolder(destinationFolder); } var filename = Path.GetFileName(currentUri.LocalPath); // If the resource is generated by a script the extension is not correct. Skip these cases. // eg.: /image.php?w=640&h=480 var allowableExtensions = new string[] { ".ico", ".css", ".jpg", ".jpeg", ".png", ".gif", ".pdf" }; if (allowableExtensions.Contains(Path.GetExtension(filename))) { var destinationFile = _storageProvider.Combine(destinationFolder, filename); if (_storageProvider.FileExists(destinationFile)) { _storageProvider.DeleteFile(destinationFile); } using (var _client = new WebClient()) { var fileData = _client.DownloadData(currentUri); using (var stream = _storageProvider.CreateFile(destinationFile).OpenWrite()) { stream.Write(fileData, 0, fileData.Length); } } // If file creation successful if (_storageProvider.FileExists(destinationFile)) { return(_storageProvider.GetPublicUrl(destinationFile)); } } return(string.Empty); }
/// <summary> /// Creates a media folder. /// </summary> /// <param name="relativePath">The path where to create the new folder. null means root.</param> /// <param name="folderName">The name of the folder to be created.</param> public void CreateFolder(string relativePath, string folderName, IUser usr) { Argument.ThrowIfNullOrEmpty(folderName, "folderName"); //Mes customized var r = usr.As <UserRolesPart>(); if (r.Roles.Any(p => p == "vendedor")) { //obtener solo sus imagenes var userFolder = _storageProvider .ListFolders(relativePath) .Select(BuildMediaFolder) .Where(f => f.Name.Equals(usr.UserName, StringComparison.OrdinalIgnoreCase)) .FirstOrDefault(); if (userFolder != null) { relativePath = userFolder.MediaPath; } } _storageProvider.CreateFolder(relativePath == null ? folderName : _storageProvider.Combine(relativePath, folderName)); }
/// <summary> /// Creates a media folder. /// </summary> /// <param name="relativePath">The path where to create the new folder. null means root.</param> /// <param name="folderName">The name of the folder to be created.</param> public void CreateFolder(string relativePath, string folderName) { Argument.ThrowIfNullOrEmpty(folderName, "folderName"); _storageProvider.CreateFolder(relativePath == null ? folderName : _storageProvider.Combine(relativePath, folderName)); }
public void createFolder_and_listFolder_shoud_contain_it() { SUT.CreateFolder(SUT.Combine(TEST_FOLDER, "folder")); Assert.AreEqual("folder", SUT.ListFolders(TEST_FOLDER).Single().GetName()); }
protected override DriverResult Editor(ContentPart part, Fields.FileField field, IUpdateModel updater, dynamic shapeHelper) { var settings = field.PartFieldDefinition.Settings.GetModel <FileFieldSettings>(); var viewModel = new FileFieldViewModel { Settings = settings, Field = field }; if (updater.TryUpdateModel(viewModel, GetPrefix(field, part), null, null)) { var postedFile = ((Controller)updater).Request.Files["FileField-" + field.Name]; AssignDefaultMediaFolder(settings); var mediaFolder = FormatWithTokens(settings.MediaFolder, part.ContentItem.ContentType, field.Name, part.ContentItem.Id); if (postedFile != null && postedFile.ContentLength != 0) { var extension = ParseFileExtenstion(postedFile.FileName); var allowedExtensions = ParseAllowedExtention(settings.ExtenstionsAllowed); var fileName = Path.GetFileNameWithoutExtension(postedFile.FileName); if (allowedExtensions.Contains(extension)) { if (postedFile.ContentLength <= (settings.MaxFileSize * 1024)) { var postedFileLength = postedFile.ContentLength; var postedFileData = new byte[postedFileLength]; var postedFileStream = postedFile.InputStream; postedFileStream.Read(postedFileData, 0, postedFileLength); try { // try to create the folder before uploading a file into it _storageProvider.CreateFolder(mediaFolder); } catch { // the folder can't be created because it already exists, continue } if (settings.NameTag == NameTags.Index) { var lastFileIndex = _storageProvider.ListFiles(mediaFolder) .Count(f => Path.GetFileNameWithoutExtension(f.GetName()).Contains(fileName)); fileName = String.Format("{0} ({1}).{2}", fileName, lastFileIndex + 1, extension); } else if (settings.NameTag == NameTags.TimeStamp) { fileName = String.Format("{0}-{1}.{2}", fileName, DateTime.Now.ToString("yyyyMMddhhmmss"), extension); } // var filePath = _storageProvider.Combine(mediaFolder, fileName); var file = _storageProvider.CreateFile(filePath); using (var fileStream = file.OpenWrite()) { fileStream.Write(postedFileData, 0, postedFileLength); } field.Path = _storageProvider.GetPublicUrl(file.GetPath()); } else { updater.AddModelError("File", T("The file size is bigger than the maximum file size, maximum size is {0}KB.", settings.MaxFileSize)); } } else { updater.AddModelError("File", T("The file type is not allowed for {0}.", postedFile.FileName)); } } else { if (settings.Required && string.IsNullOrWhiteSpace(field.Path)) { updater.AddModelError("File", T("You must provide a file for {0}.", field.Name.CamelFriendly())); } } if (string.IsNullOrWhiteSpace(field.Text)) { field.Text = Path.GetFileName(field.Path); } } return(Editor(part, field, shapeHelper)); }
public string CreateFolder(string path) { return(_storage.CreateFolder(path)); }