/* * /// <summary> * /// Sets or removes icon. * /// </summary> * /// <param name="set">True to display the icon. False - to remove the icon.</param> * private async Task SetIconAsync(bool set, int? id = null, string iconFile = null, string description = null) * { * IStorageItem storageItem = await FsPath.GetStorageItemAsync(userFileSystemPath); * * if (storageItem == null) * { * // This method may be called on temp files, typically created by MS Office, that exist for a short period of time. * // StorageProviderItemProperties.SetAsync(null,) causes AccessViolationException * // which is not handled by .NET (or handled by HandleProcessCorruptedStateExceptions) and causes a fatal crush. * return; * } * * try * { * if (set) * { * StorageProviderItemProperty propState = new StorageProviderItemProperty() * { * Id = id.Value, * Value = description, * IconResource = Path.Combine(virtualDrive.Settings.IconsFolderPath, iconFile) * }; * await StorageProviderItemProperties.SetAsync(storageItem, new StorageProviderItemProperty[] { propState }); * } * else * { * await StorageProviderItemProperties.SetAsync(storageItem, new StorageProviderItemProperty[] { }); * } * } * * // Setting status icon failes for blocked files. * catch (FileNotFoundException) * { * * } * catch (COMException) * { * // "Error HRESULT E_FAIL has been returned from a call to a COM component." * } * catch (Exception ex) * { * if (ex.HResult == -2147024499) * { * // "The operation failed due to a conflicting cloud file property lock. (0x8007018D)" * } * else * { * // Rethrow the exception preserving stack trace of the original exception. * System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(ex).Throw(); * } * } * } */ /// <summary> /// Sets or removes read-only attribute on files. /// </summary> /// <param name="set">True to set the read-only attribute. False - to remove the read-only attribute.</param> public async Task <bool> SetLockedByAnotherUserAsync(bool set) { bool resultSet = false; // Changing read-only attribute on folders triggers folders listing. Changing it on files only. if (FsPath.IsFile(userFileSystemPath)) { FileInfo file = new FileInfo(userFileSystemPath); if (set != file.IsReadOnly) { // Set/Remove read-only attribute. if (set) { new FileInfo(userFileSystemPath).Attributes |= System.IO.FileAttributes.ReadOnly; } else { new FileInfo(userFileSystemPath).Attributes &= ~System.IO.FileAttributes.ReadOnly; } resultSet = true; } } return(resultSet); }
public static FileSystemItemTypeEnum GetItemType(string path) { return(FsPath.IsFile(path) ? FileSystemItemTypeEnum.File : FileSystemItemTypeEnum.Folder); }