/// <summary> /// liefert das DocumentFile für eine Datei oder ein Verzeichnis (API level 14) /// <para>Wenn das Objekt noch nicht ex., wird es erzeugt. Auch ein notwendiger Pfad wird vollständig erzeugt.</para> /// </summary> /// <param name="storagename">z.B. "primary" oder "19F4-0903"</param> /// <param name="volpath">abs. Pfad im Volume</param> /// <param name="isDirectory">Pfad bezieht sich auf eine Datei oder ein Verzeichnis</param> /// <returns></returns> public DocumentFile GetDocumentFile(string storagename, string volpath, bool isDirectory) { global::Android.Net.Uri rooturi = GetTreeDocumentUri(storagename); DocumentFile document = DocumentFile.FromTreeUri(Activity.ApplicationContext, rooturi); string[] pathelems = volpath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; document != null && i < pathelems.Length; i++) { DocumentFile nextDocument = document.FindFile(pathelems[i]); if (nextDocument == null) { if ((i < pathelems.Length - 1) || isDirectory) { nextDocument = document.CreateDirectory(pathelems[i]); } else { nextDocument = document.CreateFile("", pathelems[i]); } } document = nextDocument; } System.Diagnostics.Debug.WriteLine("AndroidGetDocumentFile(" + storagename + ", " + volpath + ", " + isDirectory.ToString() + ") = " + (document != null && (isDirectory == document.IsDirectory)).ToString()); return(document != null ? (isDirectory == document.IsDirectory ? document : null) : null); }
public async Task <IFolder> CreateFolderAsync(string desiredName, CreationCollisionOption option, CancellationToken cancellationToken = default(CancellationToken)) { desiredName = await EnsureExistence(desiredName, option, cancellationToken); var newFolder = folder.CreateDirectory(desiredName); return(new AndroidFolder(context, newFolder, this)); }
public override async Task <StorageFolder> CreateFolderAsync(string folderName, Windows.Storage.CreationCollisionOption option, CancellationToken token) { return(await Task.Run(async() => { var existingItem = await TryGetItemAsync(folderName, token); switch (option) { case CreationCollisionOption.ReplaceExisting: if (existingItem is StorageFile) { throw new UnauthorizedAccessException("There is already a file with the same name."); } if (existingItem is StorageFolder folder) { // Delete existing folder recursively await folder.DeleteAsync(); } break; case CreationCollisionOption.FailIfExists: if (existingItem != null) { throw new UnauthorizedAccessException("There is already an item with the same name."); } break; case CreationCollisionOption.OpenIfExists: if (existingItem is StorageFolder existingFolder) { return existingFolder; } if (existingItem is StorageFile) { throw new UnauthorizedAccessException("There is already a file with the same name."); } break; case CreationCollisionOption.GenerateUniqueName: folderName = await FindAvailableNumberedFolderNameAsync(folderName); break; default: throw new ArgumentOutOfRangeException(nameof(option)); } var directoryDocument = _directoryDocument.CreateDirectory(folderName); return GetFromSafDocument(directoryDocument); }, token)); }