I am trying to search for a file with a given name from a given root directory using the code below
Dim searchPattern As String = fileNameWithoutExtension.TrimEnd & "*"
Dim foundFiles As String() = Directory.GetFiles(Path.Combine("\\?", directoryPath),
searchPattern, SearchOption.AllDirectories)
I am able to do this without any issues when I run the vb.net application from visual studio. But, getting the below error when I running it as a published Windows application.
Illegal characters in path.
Stack Trace
at
System.Security.Permissions.FilelOPermission.EmulateFilelOPermission Checks(String fullPath)
at System.IO.FileSystemEnumerableIterator 1..ctor(String path, String original UserPath,
String searchPattern, SearchOption searchOption, SearchResultHandler 1 resultHandler, Boolean
checkHost)
at System.IO.Directory.GetFiles(String path, String SearchPattern,
SearchOption searchOption) at Fluence PanelSchedule.ProjectDocumentCreator.SearchFile(String
projectName, String docName, List 1 tempArrayFilesNotFound) Source::
\\?\C:\Users\username\directoryA\10_Document files.
The prefix \\?\
is added to avoid longer file path issues. And there is no other special character present in the file path.
What am I missing here?