Long path support with file system watcher

Jalps 1 Reputation point
2022-02-21T15:00:07.267+00:00

In our client application implemented in C# with .Net framework 4.8 (OS: Windows 10), we are using file system watcher control to detect folder's events. To support a long path we have tried with \?\ in folder path. When we create a new file in long path, file system watcher detects "Created" event and it returns correct format of full path. However when we delete the file from long path, watcher control's "Deleted" event fires but it returns the full path having ~ tilde in folder's names and in file name. e.g \?\C:\abc\FIRSTF~1\SECOND~1\THIRDF~1\FOURTH~1\FIFTHF~1....\AVIA~1.jpg

We have tried below win32 method to get correct full path, however its not returning full path, [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] private static extern Int32 GetLongPathName(String shortPath, StringBuilder longPath, Int32 longPathLength);

Can anybody please suggest is there any upgrade version of file system watcher control to support long path or any other alternatives to get correct long path on file's delete or rename event? Any help would be appreciated.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,268 questions
{count} votes