BCDeWitt
BCDeWitt

Reputation: 4773

Problem with Illegal Characters in SQL Server Assembly

I am working with Directory.GetFiles in C#. This code is turned into an assembly which is then used in a T-SQL script. Here is the code line that I believe is the problem:

C# Code:

string[] filePaths = Directory.GetFiles(path, ext, SearchOption.AllDirectories);

Error (T-SQL script):

System.IO.DirectoryNotFoundException: Could not find a part of the path 'G:\Photography\Archive\SPBKF3~L'.

I'm assuming the tilde isn't a legal character to use for a folder name in Windows because the only folders that cause this error are the ones with a tilde. The files are being shared between Mac and Windows systems and I've found that file and folder names have been a problem in the past.

I'm having a difficult time understanding why the Directory.GetFiles method would even find a directory that doesn't exist. The folder displays in Windows Explorer but I cannot access the folder.

Is there something I can do to avoid these problem folders?

Upvotes: 2

Views: 436

Answers (3)

Moose
Moose

Reputation: 5412

SPBKF3~L looks suspiciously like an 8.3 shortened filename. Are you sure this isn't happening somewhere?

Upvotes: 3

tomfanning
tomfanning

Reputation: 9660

Check the permissions on G:\Photography\Archive\SPBKF3~L and ensure that the user account the SQL Server instance is running under can see the folder.

Upvotes: 2

Justin
Justin

Reputation: 86729

~ is not an invalid character - I just tried creating a directory with the name SPBKF3~L, and I also wrote up a quick C# app to run your sample code on that directory and it worked fine.

There must be something else happening here - are you absolutely sure that the directory exists? (try copying and pasting the path into an explorer window)

Upvotes: 2

Related Questions