Hello @FrogsHunter , Welcome to Microsoft Q&A,
Please note that HoloLens App is also a UWP app and UWP apps can only access certain file system locations by default. Your app does not have access to most of the file system. For more details, please see File access permissions.
It's recommended to let the user select the folder location by using a file picker. For more info, see Open files and folders with a picker. When your app retrieves the folder via picker, you can add it to the FutureAccessList so that your app can readily access that item in the future.
void SelectFolder()
{
#if ENABLE_WINMD_SUPPORT
UnityEngine.WSA.Application.InvokeOnUIThread(async () =>
{
var folderPicker = new Windows.Storage.Pickers.FolderPicker();
folderPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
folderPicker.FileTypeFilter.Add("*");
Windows.Storage.StorageFolder folder = await folderPicker.PickSingleFolderAsync();
if (folder != null)
{
// Application now has read/write access to all contents in the picked folder
// (including other sub-folder contents)
Windows.Storage.AccessCache.StorageApplicationPermissions.
FutureAccessList.AddOrReplace("PickedFolderToken", folder);
}
}, false);
#endif
}
Then you can create file and write to it as per Create, write, and read a file.
async void SaveFile()
{
#if ENABLE_WINMD_SUPPORT
if (Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.ContainsItem("PickedFolderToken"))
{
Windows.Storage.StorageFolder storageFolder = await Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.GetFolderAsync("PickedFolderToken");
Windows.Storage.StorageFile sampleFile = await storageFolder.CreateFileAsync("sample.txt", Windows.Storage.CreationCollisionOption.OpenIfExists);
await Windows.Storage.FileIO.WriteTextAsync(sampleFile, "Swift as a shadow");
}
#endif
}
----
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.