File.Copy

R

rgw1

Hello,

Can anyone help with this?

I am using C# with IIS 6.0 on Windows 2003 Server. I am trying to copy
a file over the network. It is attempting to copy a file on a NAS
(external hard drive), which is Linux based. I have already set the
permission on the NAS and I can copy files manually without any
problem. If I run the same code on IIS 5.1 on Windows XP on the same
network, it works!

Here is the complete code:

<% @Page Language="C#" Debug="true" %>

<script runat="server">

void Page_Load(object sender, EventArgs e)
{
try
{
System.IO.File.Copy(@"\\Hd-land14\library\test.doc", @"\\Hd-
land14\library\test2.doc");
}
catch (Exception ex)
{
Response.Write(ex);
}
}

</script>

Here is the error:

System.IO.IOException: Logon Failure: unknown user name or bad
password. System.IO.__Error.WinIOError(Int32 errorCode, String
maybeFullPath) System.IO.File.InternalCopy(String sourceFileName,
String destFileName, Boolean overwrite) System.IO.File.Copy(String
sourceFileName, String destFileName) ASP.test_aspx.Page_Load(Object
sender, EventArgs e) c:\Inetpub\wwwroot\test.aspx: line 49

Any information will appreciated.

Thanks!!
 
P

Peter Duniho

Hello,

Can anyone help with this?

I am using C# with IIS 6.0 on Windows 2003 Server. I am trying to copy
a file over the network. It is attempting to copy a file on a NAS
(external hard drive), which is Linux based. I have already set the
permission on the NAS and I can copy files manually without any
problem. If I run the same code on IIS 5.1 on Windows XP on the same
network, it works!

When you are testing it on the other system, are you using the same
exact user ID and password?

The exception looks like a straight permissions problem. Windows file
security can be kind of quirky, so it's hard to say exactly without
more information what a precise solution to a permissions problem would
be (depending on the configuration of the network, you might need to
have an exact NT domain account, or just log in with the right username
and password, or provide the necessary credentials via "net use",
or...).

But as a general rule, if you've got a system from which you can access
the file, and one from which you can't, it's possible that you're just
using different credentials on each system. Use the same working set
of credentials on both, and it should work.

Of course, this means it doesn't really have anything to do with the C#
code per se. But close enough. :)

Pete
 
C

christery

When you are testing it on the other system, are you using the same
exact user ID and password?

The exception looks like a straight permissions problem. Windows file
security can be kind of quirky, so it's hard to say exactly without
more information what a precise solution to a permissions problem would
be (depending on the configuration of the network, you might need to
have an exact NT domain account, or just log in with the right username
and password, or provide the necessary credentials via "net use",
or...).

But as a general rule, if you've got a system from which you can access
the file, and one from which you can't, it's possible that you're just
using different credentials on each system. Use the same working set
of credentials on both, and it should work.

Of course, this means it doesn't really have anything to do with the C#
code per se. But close enough. :)

Pete

Nope, imho u are providing the poor machine an URL.... llose the @ or
format the code correct

In the context of strings, the @ symbol is used to create verbatim
string literals. The @ symbol tells the string constructor to use the
string literal that follows it "literally"--even if it includes escape
characters or spans multiple lines.

This comes in handy when working with directory paths (without the @,
you would have to double each backslash). For example, the following
two strings are equivalent:

string noat = "\\\\BIGSERVER\\C";
string withat = @"\\BIGSERVER\C";

//CY
 
C

christery

Nope, imho u are providing the poor machine an URL.... llose the @ or
format the code correct

In the context of strings, the @ symbol is used to create verbatim
string literals. The @ symbol tells the string constructor to use the
string literal that follows it "literally"--even if it includes escape
characters or spans multiple lines.

This comes in handy when working with directory paths (without the @,
you would have to double each backslash). For example, the following
two strings are equivalent:

string noat = "\\\\BIGSERVER\\C";
string withat = @"\\BIGSERVER\C";

//CY- Dölj citerad text -

- Visa citerad text -

Oops, just saw its correct... sorry about that...

//CY
 
C

christery

problem. If I run the same code on IIS 5.1 on Windows XP on the same
just at thougt, the IIS service, is it set up the same way? service
logged in as... in controlpanel/administrative/services the file copy
should be in the security context of the service logged in.

//CY
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top