Help with unc paths

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I am new to C# and am having a problem with my program. I have created a
small test to try and find the problem but I can't seem to find it. The
following code is my test.

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test
{
class Program
{
static private string driveletter = "H:\\corp\\";
static private string uncpath = "\\\\lrlcadd03\\corp\\";
static void Main()
{
// This line works fine.
File.Copy(driveletter + "test.txt", driveletter + "my.txt");

//This line produces the error.
File.Copy(uncpath + "test.txt", uncpath + "my1.txt");
}
}
}

Can anyone tell me why the unc path is not working?
 
Hello,

I am new to C# and am having a problem with my program. I have created a
small test to try and find the problem but I can't seem to find it. The
following code is my test.

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test
{
class Program
{
static private string driveletter = "H:\\corp\\";
static private string uncpath = "\\\\lrlcadd03\\corp\\";
static void Main()
{
// This line works fine.
File.Copy(driveletter + "test.txt", driveletter + "my.txt");

//This line produces the error.
File.Copy(uncpath + "test.txt", uncpath + "my1.txt");
}
}

}

Can anyone tell me why the unc path is not working?

After a quick inspection, I can't see anything wrong with the code.
What error do you get? The second File.Copy may be starting before
the first one is completed. What happens if you reverse the order of
the two File.Copy commands? i. e. try to copy the unc path first.

Chris
 
This is the error message:

Unhandled Exception: System.IO.IOException: The network path was not found.

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String
destFileName, Bo
olean overwrite)
at test.Program.Main() in C:\Documents and Settings\h2edtglp\My
Documents\Vis
ual Studio 2008\Projects\test\test\Program.cs:line 16
Press any key to continue . . .

I get this error message reguardless of the position of the call. Forgot to
mention this earlier I am using the 2008 Express Edition of C#.
 
That means that the path is invalid (uncpath).
You need to make sure that "lrlcadd03" is a valid server name and that
"corp" is a valid exported share.
What happens when you run "dir \\lrlcadd03\corp" from a command prompt?

Willy.
 
Man I feel stupid. I found and fixed my problem. I was missing a directory in
the path.

Thanks to all of you that helped.
--
Gerald Piotrowski


Willy Denoyette said:
That means that the path is invalid (uncpath).
You need to make sure that "lrlcadd03" is a valid server name and that
"corp" is a valid exported share.
What happens when you run "dir \\lrlcadd03\corp" from a command prompt?

Willy.
 
Back
Top