I want to use DirectoryInfo and Fileinfo in uwp for external folders on windows 10. First, I select folder by picker and get access for StorageFolder. Next I try to set, for example, LastWriteTime:
DirectoryInfo directoryInfo = new DirectoryInfo(storageFolder.Path);
directoryInfo.LastWriteTime = DateTime.Now;
It works for local app folders, but for external folders I recieve error "Access to the path -||- is denied". Is it generally possible what I want? Are there any workarounds?
Can I use system.io in uwp for external folders when I get access by picker?
The short answer is no. DirectoryInfo
is under system.io namespace, it has no permission to access DirectoryInfo
with path.
For your requirement, we suggest you use desktop bridge to approach, and edit directoryInfo in desktop extension.
For example
Wpf extension
System.Windows.Forms.FolderBrowserDialog openFileDlg = new System.Windows.Forms.FolderBrowserDialog();
var result = openFileDlg.ShowDialog();
if (result.ToString() != string.Empty)
{
DirectoryInfo directoryInfo = new DirectoryInfo(openFileDlg.SelectedPath);
directoryInfo.LastWriteTime = DateTime.Now;
}