Search code examples
c#ioparallels

Why can't File.OpenRead see my network location?


I've just got a new Mac and switched my development to a Windows VM. I'm trying to copy a large (218 mb) txt file from one network location to another, while making modifications to it's contents. I am connecting to the network drive with my mac, but the windows instance doesn't seem to see it. Here is the code that throws the error (sourceFile is something like"\\networkpath\thefile.txt"):

    using (var inputStream = File.OpenRead(sourceFile))
        {
            using (var inputReader = new StreamReader(inputStream))
            {
                using (var outputWriter = File.AppendText(destFile))
                {
                    string tempLineValue;
                    while (null != (tempLineValue = inputReader.ReadLine()))
                    {
                        var replace = tempLineValue.Replace('\t', '\0');
                        outputWriter.WriteLine(replace);
                    }
                }
            }
        }

The error is "System.IO.IOException {The network path was not found.\r\n}". This exception is thrown when stepping through the File.OpenRead method. If any of you guys or gals could point me in the right direction, I'd be grateful.


Solution

  • One approach is to map the location as a network drive and then use the mapped device as start path to the file.

    Also you can check if the user that is currently trying to open the file has some rights to the network path.