I want to be able to create files and folders inside of LocalCacheFolder
without worrying that the total path length will be over 248 characters, which is currently a problem in my app. What is a good way to deal with this, besides making my app generate shorter paths and avoiding nesting?
Additional context:
I've found that WinRT apps are susceptible to MAX_PATH limitations. In my app, when calling StorageFolder.CreateFileAsync
I get a System.IO.PathTooLongException
with the message:
"The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters."
This happens quite often when creating a few nested subfolders inside of Windows.Storage.ApplicationData.Current.LocalCacheFolder
, because the LocalCacheFolder is actually C:\Data\Users\DefApps\APPDATA\Local\Packages\<my_package>\LocalCache\
, and thus, the number of characters allowed in my own app-created folder/files is greatly reduced.
What I have tried:
Given the background in this article, I attempted the following to see if I could trick WinRT into using a Win32 file namespace, which would theoretically give me Unicode paths with a max length of 32,767 characters:
var path = Windows.Storage.ApplicationData.Current.LocalCacheFolder.Path;
var cacheFolder = await StorageFolder.GetFolderFromPathAsync(@"\\?\" + p);
This attempt fails with an exception: The specified path is invalid. (Exception from HRESULT: 0x800700A1)
. So now I am out of ideas.
.NET doesn't support the \?\ file paths. You'll need to rely on short file names.
It sucks, but there a MSKB on the topic: http://support.microsoft.com/kb/142982
User contributions licensed under CC BY-SA 3.0