open network file

  • Thread starter Thread starter Lam
  • Start date Start date
L

Lam

HI
anyone knows how can I open a mapped network file in C#?
I try string file = @"T:\file.txt"; it shows me the error: "Could not find
a part of the path"
but if I copy the file to my C dirve, and use @"C:\file.txt"; it worked

Thanks a lot
 
Lam,

Are you sure that the drive mapping is available? If the mapping is
available, you should be able to pass that filename to whatever file
routines you want, and it should work.

Is this a Windows or an ASP.NET application? If it is an ASP.NET
application, the drive mappings might not be available (most likely) to the
account that the app is running under. Also, it most likely doesn't have
the rights to access the network as well.

Hope this helps.
 
Hi,

Is T a valid network drive?

if so there is no reason for it to fail.

IIRC if your program is executing from the local computer it can access the
network.

Are you running your program from the local computer?

Beside, the error you are getting is not refering to security, so I but T is
not accesible

Unless, is this a window service? if so you have another problem, post back
if so

cheers,
 
T is the network drive to a server
it's working cause I could browse it
the project is ASP.Net project. I write the ASPX page in C#
the application is running in local computer

so how can I make the drive available to my application?

Thanks a lot

Nicholas Paldino said:
Lam,

Are you sure that the drive mapping is available? If the mapping is
available, you should be able to pass that filename to whatever file
routines you want, and it should work.

Is this a Windows or an ASP.NET application? If it is an ASP.NET
application, the drive mappings might not be available (most likely) to the
account that the app is running under. Also, it most likely doesn't have
the rights to access the network as well.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Lam said:
HI
anyone knows how can I open a mapped network file in C#?
I try string file = @"T:\file.txt"; it shows me the error: "Could not
find
a part of the path"
but if I copy the file to my C dirve, and use @"C:\file.txt"; it worked

Thanks a lot
 
Lam,

Since it is an ASP.NET project, by default, the code runs under the
ASPNET local account, which does not have access to the network. Also, by
default, that user (ASPNET) will not have the drive mapping.

Can you use the UNC name instead? It would be much easier this way.
Once you have that, you have to make sure that the code has the appropriate
permissions to access the network. To do this, you will have to add the
<identity> tag to your web.config file, indicating the account you want to
impersonate. However, this might be too broad, since all code in that
directory will run under that account. A better way would be to use the
WindowsImpersonationContext class. You can see an example of how to do this
in the documentation for the Impersonate method on the WindowsIdentity
class.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Lam said:
T is the network drive to a server
it's working cause I could browse it
the project is ASP.Net project. I write the ASPX page in C#
the application is running in local computer

so how can I make the drive available to my application?

Thanks a lot

in
message news:[email protected]...
Lam,

Are you sure that the drive mapping is available? If the mapping is
available, you should be able to pass that filename to whatever file
routines you want, and it should work.

Is this a Windows or an ASP.NET application? If it is an ASP.NET
application, the drive mappings might not be available (most likely) to the
account that the app is running under. Also, it most likely doesn't have
the rights to access the network as well.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Lam said:
HI
anyone knows how can I open a mapped network file in C#?
I try string file = @"T:\file.txt"; it shows me the error: "Could not
find
a part of the path"
but if I copy the file to my C dirve, and use @"C:\file.txt"; it worked

Thanks a lot
 
Hi,

Normally you can use the UNC for the network share, now as nicholas said
the asp.net user do not have access to access the network. Either you change
the user under which the app runs or you give the asp.net user permission.


cheers,


Lam said:
T is the network drive to a server
it's working cause I could browse it
the project is ASP.Net project. I write the ASPX page in C#
the application is running in local computer

so how can I make the drive available to my application?

Thanks a lot

in
message news:[email protected]...
Lam,

Are you sure that the drive mapping is available? If the mapping is
available, you should be able to pass that filename to whatever file
routines you want, and it should work.

Is this a Windows or an ASP.NET application? If it is an ASP.NET
application, the drive mappings might not be available (most likely) to the
account that the app is running under. Also, it most likely doesn't have
the rights to access the network as well.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Lam said:
HI
anyone knows how can I open a mapped network file in C#?
I try string file = @"T:\file.txt"; it shows me the error: "Could not
find
a part of the path"
but if I copy the file to my C dirve, and use @"C:\file.txt"; it worked

Thanks a lot
 
right now it's using "IUSR" in my computer for anonymous access
is it the user that need to be assgined the right to access the network
drive?
I try to open the security tab on T drive (mapped network drive), I don't
see any place
where I can change the permissoin for IUSR, Do I need to change the user to
be the one
from domain or from my local computer? I also try to change the user to the
current user logged
on to the computer, it still don't work

thanks a lot for your guys' help

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

Normally you can use the UNC for the network share, now as nicholas said
the asp.net user do not have access to access the network. Either you change
the user under which the app runs or you give the asp.net user permission.


cheers,


Lam said:
T is the network drive to a server
it's working cause I could browse it
the project is ASP.Net project. I write the ASPX page in C#
the application is running in local computer

so how can I make the drive available to my application?

Thanks a lot

in
message news:[email protected]...
Lam,

Are you sure that the drive mapping is available? If the mapping is
available, you should be able to pass that filename to whatever file
routines you want, and it should work.

Is this a Windows or an ASP.NET application? If it is an ASP.NET
application, the drive mappings might not be available (most likely) to the
account that the app is running under. Also, it most likely doesn't have
the rights to access the network as well.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

HI
anyone knows how can I open a mapped network file in C#?
I try string file = @"T:\file.txt"; it shows me the error: "Could not
find
a part of the path"
but if I copy the file to my C dirve, and use @"C:\file.txt"; it worked

Thanks a lot
 
No, IUSR_xxxx is the account used to access local resources while
"impersonating" anonymous clients, it's a local account so it can't be used
to access network resources. Note that this account is meant to be used by
asp application, asp.net should use the config.web file to configure the
"anonymous" account.
ASPNET is a service account, so again it's a local account and as such isn't
used to authenticate. However, if the server running asp.net is a AD domain
member (W2K or more), the credentials used to authenticate are the machine
account credentials (domain\machinename$).
Here are a few options in order of complexity, note that all depends on the
OS you are running on the webserver and the network environment (domain, no
domain):
- When running in a domain (but I guess you are not), set the impersonating
account in your web.config file to a domain account with access privileges
to the share.
- When running in a workgoup, you have to set the impersonating account in
your web.config file to the same account as used when connecting from your
interactive session.
- Another option is to create a new logon session in code (calling
LogonUser() to obtain a logon token) and impersonate the logon token when
accessing the remote share, note that this requires PInvoke interop calls
(LogonUser()).
- You can also create a "use record", that is map the network share in code,
but this also requires PInvoke interop calls.
- And yet another option is to store the remote access code in a COM+
application that runs with fixed credentials having remote share access
privileges.

Willy.



Lam said:
right now it's using "IUSR" in my computer for anonymous access
is it the user that need to be assgined the right to access the network
drive?
I try to open the security tab on T drive (mapped network drive), I don't
see any place
where I can change the permissoin for IUSR, Do I need to change the user
to
be the one
from domain or from my local computer? I also try to change the user to
the
current user logged
on to the computer, it still don't work

thanks a lot for your guys' help

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote
in message news:[email protected]...
Hi,

Normally you can use the UNC for the network share, now as nicholas said
the asp.net user do not have access to access the network. Either you change
the user under which the app runs or you give the asp.net user
permission.


cheers,


Lam said:
T is the network drive to a server
it's working cause I could browse it
the project is ASP.Net project. I write the ASPX page in C#
the application is running in local computer

so how can I make the drive available to my application?

Thanks a lot

"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote
in
message Lam,

Are you sure that the drive mapping is available? If the mapping is
available, you should be able to pass that filename to whatever file
routines you want, and it should work.

Is this a Windows or an ASP.NET application? If it is an ASP.NET
application, the drive mappings might not be available (most likely)
to
the
account that the app is running under. Also, it most likely doesn't have
the rights to access the network as well.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

HI
anyone knows how can I open a mapped network file in C#?
I try string file = @"T:\file.txt"; it shows me the error: "Could not
find
a part of the path"
but if I copy the file to my C dirve, and use @"C:\file.txt"; it worked

Thanks a lot
 
Hey Willy

When I look at the Web.config file, I see
<authorization>
<allow users="*" /> <!-- Allow all users -->
<!-- <allow users="[comma separated list of roles]"
roles="[comma separated list of roles]"/>
<deny users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
-->
</authorization>

is it where I change the user? and how?
right now I am running server 2003 , and it's the member of our domain
my user acount is one of the domain acounts

Thanks a lot for your help


Willy Denoyette said:
No, IUSR_xxxx is the account used to access local resources while
"impersonating" anonymous clients, it's a local account so it can't be used
to access network resources. Note that this account is meant to be used by
asp application, asp.net should use the config.web file to configure the
"anonymous" account.
ASPNET is a service account, so again it's a local account and as such isn't
used to authenticate. However, if the server running asp.net is a AD domain
member (W2K or more), the credentials used to authenticate are the machine
account credentials (domain\machinename$).
Here are a few options in order of complexity, note that all depends on the
OS you are running on the webserver and the network environment (domain, no
domain):
- When running in a domain (but I guess you are not), set the impersonating
account in your web.config file to a domain account with access privileges
to the share.
- When running in a workgoup, you have to set the impersonating account in
your web.config file to the same account as used when connecting from your
interactive session.
- Another option is to create a new logon session in code (calling
LogonUser() to obtain a logon token) and impersonate the logon token when
accessing the remote share, note that this requires PInvoke interop calls
(LogonUser()).
- You can also create a "use record", that is map the network share in code,
but this also requires PInvoke interop calls.
- And yet another option is to store the remote access code in a COM+
application that runs with fixed credentials having remote share access
privileges.

Willy.



Lam said:
right now it's using "IUSR" in my computer for anonymous access
is it the user that need to be assgined the right to access the network
drive?
I try to open the security tab on T drive (mapped network drive), I don't
see any place
where I can change the permissoin for IUSR, Do I need to change the user
to
be the one
from domain or from my local computer? I also try to change the user to
the
current user logged
on to the computer, it still don't work

thanks a lot for your guys' help

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote
in message news:[email protected]...
Hi,

Normally you can use the UNC for the network share, now as nicholas said
the asp.net user do not have access to access the network. Either you change
the user under which the app runs or you give the asp.net user
permission.


cheers,


T is the network drive to a server
it's working cause I could browse it
the project is ASP.Net project. I write the ASPX page in C#
the application is running in local computer

so how can I make the drive available to my application?

Thanks a lot

"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote
in
message Lam,

Are you sure that the drive mapping is available? If the
mapping
is
available, you should be able to pass that filename to whatever file
routines you want, and it should work.

Is this a Windows or an ASP.NET application? If it is an ASP.NET
application, the drive mappings might not be available (most likely)
to
the
account that the app is running under. Also, it most likely doesn't have
the rights to access the network as well.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

HI
anyone knows how can I open a mapped network file in C#?
I try string file = @"T:\file.txt"; it shows me the error:
"Could
not
find
a part of the path"
but if I copy the file to my C dirve, and use @"C:\file.txt"; it worked

Thanks a lot
 
Back
Top