question

Lasanga-0910 avatar image
0 Votes"
Lasanga-0910 asked NicoZhu-MSFT commented

UWP app System.IO.PathTooLongException when executing CopyAsync

I am trying to copy captured images and selected images with a file picker to a location inside App data using the StorageFile.CopyAsync() method as below.

     await photo.CopyAsync(destinationFolder, fileName, NameCollisionOption.ReplaceExisting);

I am getting below exception when I try to call photo.CopyAsync() for an image file

"System.IO.PathTooLongException: The specified file name or path is too long, or a component of the specified path is too long."

the destination path:

C:\Users\jaimecollins\AppData\Local\Packages\73ea377b-f9f3-4a64-bb17-f937c082246a_x73cm3athdc94\LocalState\17efbdca-9e18-48c1-b203-a76a71775730\5b058cfc-f7f1-42ec-afb3-4ee6b9804e0f\89d6baaa-cbc6-4ae1-8830-82dfbe14ade1

file name: 09932aeb-be37-425a-aafb-af8e2eace75f.jpg

length of the destination path is 217 and after copying with the file name it will be 258 which is less than the Max_Path length of 260

when the destination path with 212 and with the file 253 as below, there is no exceptions and the file is getting copied.
C:\Users\lasanga\AppData\Local\Packages\73ea377b-f9f3-4a64-bb17-f937c082246a_x73cm3athdc94\LocalState\17efbdca-9e18-48c1-b203-a76a71775730\5b058cfc-f7f1-42ec-afb3-4ee6b9804e0f\89d6baaa-cbc6-4ae1-8830-82dfbe14ade1


Please let me know the what is the limit for the path names and if there is any workaround to support long file paths

Thanks.




windows-uwp
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I tested with your scenario 1, (destination path is 217 and after copying with the file name it will be 258), and it works well in my side, even increase the file to double length.

0 Votes 0 ·

Have you set LongPathsEnabled = 1 in registry? or have you done any other configuration changes to enable long paths?

0 Votes 0 ·

No, I have not edited registry.

0 Votes 0 ·

1 Answer

Castorix31 avatar image
0 Votes"
Castorix31 answered Lasanga-0910 commented

On my OS (Windows 10 1909), I can create a path+file > 300 with CopyAsync and LongPathsEnabled = 1 in registry, as explained at
Maximum Path Length Limitation




· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for the answer. But this cannot be done since all the users have to set this

0 Votes 0 ·