Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > C# open file on windows share

Reply
Thread Tools

C# open file on windows share

 
 
P4trykx
Guest
Posts: n/a
 
      08-07-2007
Hello

I hace a code that opens a file on a windows share.

\\comp1\folder1\file.txt

Folder1 has full access for Everyone. I can open it from explorer on
my computer (my user isn't on set the server). However when I run this
code

FileStream file = new FileStream(serverFilePath, FileMode.Open);

from asp code as the same user as I do it form explorer I get
IOException saying that the user and password are wrong. Howto
convince C# not to login ?

--
Patryk

 
Reply With Quote
 
 
 
 
Andrew Brook
Guest
Posts: n/a
 
      08-07-2007
does this work?
System.IO.FileStream fs = new
System.IO.FileStream(serverFilePath,System.IO.File Mode.Open,System.IO.FileAccess.Read);

Andrew

"P4trykx" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Hello
>
> I hace a code that opens a file on a windows share.
>
> \\comp1\folder1\file.txt
>
> Folder1 has full access for Everyone. I can open it from explorer on
> my computer (my user isn't on set the server). However when I run this
> code
>
> FileStream file = new FileStream(serverFilePath, FileMode.Open);
>
> from asp code as the same user as I do it form explorer I get
> IOException saying that the user and password are wrong. Howto
> convince C# not to login ?
>
> --
> Patryk
>



 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      08-07-2007
Hi Patryk,

All processes run in the context of a logged-in user account. If you want to
open a file on another computer, your application must be running in the
context of a user that has permissions to open files on that machine. You
can do this with Impersonation.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"P4trykx" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Hello
>
> I hace a code that opens a file on a windows share.
>
> \\comp1\folder1\file.txt
>
> Folder1 has full access for Everyone. I can open it from explorer on
> my computer (my user isn't on set the server). However when I run this
> code
>
> FileStream file = new FileStream(serverFilePath, FileMode.Open);
>
> from asp code as the same user as I do it form explorer I get
> IOException saying that the user and password are wrong. Howto
> convince C# not to login ?
>
> --
> Patryk
>



 
Reply With Quote
 
P4trykx
Guest
Posts: n/a
 
      08-07-2007
On 7 Sie, 13:00, "Andrew Brook" <(E-Mail Removed)> wrote:
> does this work?
> System.IO.FileStream fs = new
> System.IO.FileStream(serverFilePath,System.IO.File Mode.Open,System.IO.FileA*ccess.Read);


no, I get the same Exception


--
Patryk

 
Reply With Quote
 
P4trykx
Guest
Posts: n/a
 
      08-07-2007
On 7 Sie, 13:35, "Kevin Spencer" <(E-Mail Removed)> wrote:
> All processes run in the context of a logged-in user account. If you want to
> open a file on another computer, your application must be running in the
> context of a user that has permissions to open files on that machine. You
> can do this with Impersonation.


Ok, so how does the explorer manage to open this file ?

--
Patryk

 
Reply With Quote
 
Aidy
Guest
Posts: n/a
 
      08-07-2007
Explorer is running as the logged on user, your asp.net code is running
under an account local to the machine that has no access rights to any other
machine on the network, so it cannot access files on shares. You can change
the account your anonymous users run as via the iis admin tools and set it
to an account with the appropriate permissions.

"P4trykx" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> On 7 Sie, 13:35, "Kevin Spencer" <(E-Mail Removed)> wrote:
>> All processes run in the context of a logged-in user account. If you want
>> to
>> open a file on another computer, your application must be running in the
>> context of a user that has permissions to open files on that machine. You
>> can do this with Impersonation.

>
> Ok, so how does the explorer manage to open this file ?
>
> --
> Patryk
>



 
Reply With Quote
 
P4trykx
Guest
Posts: n/a
 
      08-07-2007
On 7 Sie, 15:18, "Aidy" <(E-Mail Removed)> wrote:
> Explorer is running as the logged on user, your asp.net code is running
> under an account local to the machine that has no access rights to any other
> machine on the network,


But I'm logged as user12 and the same user is in web.config in
impersonate section

<identity impersonate="true" userName="user12" password="somePassowrd"/
>


There is no users12 on the server(comp1) with the files I want to
access. \\comp1\folder1\file.txt


--
Patryk



--
Patryk




 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      08-08-2007
Are you logged in to a domain (Active Directory) account?

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"P4trykx" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> On 7 Sie, 15:18, "Aidy" <(E-Mail Removed)> wrote:
>> Explorer is running as the logged on user, your asp.net code is running
>> under an account local to the machine that has no access rights to any
>> other
>> machine on the network,

>
> But I'm logged as user12 and the same user is in web.config in
> impersonate section
>
> <identity impersonate="true" userName="user12" password="somePassowrd"/
>>

>
> There is no users12 on the server(comp1) with the files I want to
> access. \\comp1\folder1\file.txt
>
>
> --
> Patryk
>
>
>
> --
> Patryk
>
>
>
>



 
Reply With Quote
 
P4trykx
Guest
Posts: n/a
 
      08-08-2007
On 8 Sie, 13:08, "Kevin Spencer" <(E-Mail Removed)> wrote:
> Are you logged in to a domain (Active Directory) account?


No, I have a local account.However computer on which I have the
share's is a aomain controller.

I suspect that explorer first tries to accesses the share using logged
user ant if this fails (no such user on the remote computer) it
connects using Guest account.

--
Patryk

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Share-Point-2010 ,Share-Point -2010 Training , Share-point-2010Hyderabad , Share-point-2010 Institute Saraswati lakki ASP .Net 0 01-06-2012 06:39 AM
[ANN] clogger 0.3.2 - share a hacker, share a bug Eric Wong Ruby 0 02-13-2010 10:42 AM
Re: how to open a file in some application using Tkinter i am usingTKINTER to create GUI application i want to know how to open a worddocument in open office or any other applicatio Fredrik Lundh Python 1 01-09-2008 10:40 AM
question DRb class definition share or not share Jack Ruby 2 10-11-2007 05:26 PM
Wireless Network - Setup - How? See/share Files, share printers, how? Wayne Wireless Networking 2 04-08-2006 04:34 PM



Advertisments