0

I am trying to rename a file on a network drive and I have found this:

Rename a file in C#

I have found numerous links about this error. Unfortunately, it hasn't fixed my issue.

This is the code that I have tried:

var XMLFile = @"\ServerName\DriveName\NprintDevelopment\ExternalRequestsXML\";
var XMLOldExtension = "CallNPrintReport.processed";
var XMLNewExtension = "CallNPrintReport.reques";

if (File.Exists(XMLFile + XMLOldExtension))
{
    File.Copy(XMLFile + XMLOldExtension, XMLFile + XMLNewExtension, false);
    File.Delete(XMLFile + XMLOldExtension);
}

I also tried:

var XMLFile = "\\ServerName\\DriveName\\NprintDevelopment\\ExternalRequestsXML\\";
var XMLOldExtension = "CallNPrintReport.processed";
var XMLNewExtension = "CallNPrintReport.reques";

What am I missing? It is probably just something dumb but don't see the issue.

djblois
  • 963
  • 1
  • 17
  • 52
  • Is this a console app or a web app? – DavidG May 30 '18 at 15:32
  • @DavidG Console App – djblois May 30 '18 at 15:33
  • You need a double slash at the start to specify the server e.g. `\\servername\path`. Also, `DriveName` needs to be a share name, is it a share on your server? – DavidG May 30 '18 at 15:35
  • @DavidG, I tried that also and then I get the error 'The network name cannot be found' – djblois May 30 '18 at 15:41
  • Like I said, you cannot just specify `DriveName`, that folder needs to be a network share. Can you access the file by putting that string into Windows Explorer? – DavidG May 30 '18 at 15:42
  • @DavidG, no so how do I access the D drive on a different server? I tried looking for that and all I found was to access it by drive name. – djblois May 30 '18 at 15:44
  • I've said it twice now, you need to share a folder on the server, preferably not the whole drive, just the `ExternalRequestsXML` folder for example and use `\\server\ExternalRequestsXML\CallNPrintReport.processed` – DavidG May 30 '18 at 15:45
  • thank you; I will get my IT to set up a folder share – djblois May 30 '18 at 15:47

0 Answers0