UWP app System.IO.PathTooLongException when executing CopyAsync

Lasanga 1 Reputation point

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:


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.

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


Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 83,021 Reputation points

    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