I am trying to open a file on a UNC path. The computer name in the UNC
path contains spaces. The FileStream constructor throws a "Network
access denied" IOException.
try
{
FileStream fs = new FileStream("\\comp with
space\inbox\readme.txt", FileMode.Open);
}
catch(IOException ex)
{
Console.WriteLine(ex.Message); // outputs "Network access is
denied."
}
However, if I use the FileInfo.OpenRead() to open the file, I can
successfully get a FileStream!
FileInfo fi = new FileInfo("\\comp with space\inbox\readme.txt");
Using(FileStream fs = fi.OpenRead())
{
byte [] content = new byte[fs.Length];
fs.Read(content, 0, (int)fs.Length);
}
Anybody faced this problem before?
Thanks
Deepak
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.