Reputation: 65
For searching files in a directory, I am using this snippet of code :
string targetToCopy = ConfigurationManager.AppSettings["drive"] + element.Element("categorie").Value.ToString().Replace(" / ", @"\");
DirectoryInfo directoryToCopy = new DirectoryInfo(targetToCopy);
I create the path with this string targetToCopy
, I parse the string in DirectoryInfo
for using the directoryToCopy.GetFiles()
method.
This method searches files with path, and when I use this in my loop, I get an error:
System.NotSupportedException : 'The format of the given path is not supported.'
I don't know what this error means, but if you know how to solve the problem.
Thank you and good luck :)
Upvotes: 1
Views: 1240
Reputation: 6499
There is a space before the /
in Replace(" / ", @"\")
therefore String.Replace
transformation is not in effect
Updated code
string targetToCopy = ConfigurationManager.AppSettings["drive"] + element.Element("categorie").Value.ToString().Replace("/ ", @"\");
Upvotes: 1
Reputation: 208
I determined the problem by outputting my path to a log file, and finding it not formatting correctly. Correct for me was quite simply:
DirectoryInfo diTemp = new DirectoryInfo(strSomePath);
FileStream fsTemp = new FileStream(diTemp.FullName.ToString());
Upvotes: 1