By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,505 Members | 1,165 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,505 IT Pros & Developers. It's quick & easy.

open network file

P: n/a
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

Nov 17 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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]
- mv*@spam.guard.caspershouse.com

"Lam" <ja**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
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

Nov 17 '05 #2

P: n/a
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Lam" <ja**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
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

Nov 17 '05 #3

P: n/a
Lam
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]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uG**************@TK2MSFTNGP10.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Lam" <ja**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
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


Nov 17 '05 #4

P: n/a
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]
- mv*@spam.guard.caspershouse.com

"Lam" <ja**********@hotmail.com> wrote in message
news:eR**************@tk2msftngp13.phx.gbl...
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]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:uG**************@TK2MSFTNGP10.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Lam" <ja**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
> 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
>
>
>



Nov 17 '05 #5

P: n/a
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" <ja**********@hotmail.com> wrote in message
news:eR**************@tk2msftngp13.phx.gbl...
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]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:uG**************@TK2MSFTNGP10.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Lam" <ja**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
> 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
>
>
>



Nov 17 '05 #6

P: n/a
Lam
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:eW*************@TK2MSFTNGP09.phx.gbl...
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" <ja**********@hotmail.com> wrote in message
news:eR**************@tk2msftngp13.phx.gbl...
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]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:uG**************@TK2MSFTNGP10.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Lam" <ja**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
> 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
>
>
>



Nov 17 '05 #7

P: n/a
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" <ja**********@hotmail.com> wrote in message
news:eB**************@TK2MSFTNGP10.phx.gbl...
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:eW*************@TK2MSFTNGP09.phx.gbl...
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" <ja**********@hotmail.com> wrote in message
news:eR**************@tk2msftngp13.phx.gbl...
>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]" <mv*@spam.guard.caspershouse.com>
> wrote
> in
> message news:uG**************@TK2MSFTNGP10.phx.gbl...
>> 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]
>> - mv*@spam.guard.caspershouse.com
>>
>> "Lam" <ja**********@hotmail.com> wrote in message
>> news:%2****************@TK2MSFTNGP14.phx.gbl...
>> > 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
>> >
>> >
>> >
>>
>>
>
>



Nov 17 '05 #8

P: n/a
Lam
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 [MVP]" <wi*************@telenet.be> wrote in message
news:#j**************@TK2MSFTNGP10.phx.gbl...
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" <ja**********@hotmail.com> wrote in message
news:eB**************@TK2MSFTNGP10.phx.gbl...
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:eW*************@TK2MSFTNGP09.phx.gbl...
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" <ja**********@hotmail.com> wrote in message
news:eR**************@tk2msftngp13.phx.gbl...
>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]" <mv*@spam.guard.caspershouse.com>
> wrote
> in
> message news:uG**************@TK2MSFTNGP10.phx.gbl...
>> 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]
>> - mv*@spam.guard.caspershouse.com
>>
>> "Lam" <ja**********@hotmail.com> wrote in message
>> news:%2****************@TK2MSFTNGP14.phx.gbl...
>> > 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
>> >
>> >
>> >
>>
>>
>
>



Nov 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.