473,324 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

C# open file on windows share

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

Aug 7 '07 #1
6 9035
does this work?
System.IO.FileStream fs = new
System.IO.FileStream(serverFilePath,System.IO.File Mode.Open,System.IO.FileAccess.Read);

Andrew

"P4trykx" <pa**********@gmail.comwrote in message
news:11**********************@b79g2000hse.googlegr 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

Aug 7 '07 #2
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" <pa**********@gmail.comwrote in message
news:11**********************@b79g2000hse.googlegr 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

Aug 7 '07 #3
On 7 Sie, 13:00, "Andrew Brook" <yko...@hotmail.comwrote:
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

Aug 7 '07 #4
On 7 Sie, 13:35, "Kevin Spencer" <unclechut...@nothinks.comwrote:
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

Aug 7 '07 #5
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" <pa**********@gmail.comwrote in message
news:11**********************@o61g2000hsh.googlegr oups.com...
On 7 Sie, 13:35, "Kevin Spencer" <unclechut...@nothinks.comwrote:
>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

Aug 7 '07 #6
On 8 Sie, 13:08, "Kevin Spencer" <unclechut...@nothinks.comwrote:
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

Aug 8 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: N. Graves | last post by:
Help me please? I'm have users import tables from other Access Database in one of the process needed to use my ADB. To do this the user opens a form with a field for the file directory and...
4
by: Lenard Gunda | last post by:
Hello! I have created a program, that receives files, and then stores them locally for later access. This program is run on a Windows 2000 Server computer as a system service. Some of the files...
2
by: nissiml | last post by:
hi, i'm trying to open a asp.net web page that list files from a Windows application like winword and select a file from it . what do i have to do to make it happen, is it simple ? Thanks in...
0
by: Me | last post by:
I have an application that has a text box. At the end on the text box is the standard elypsis (command button) for launching the Open File Dialog box. I want the user to select a certain executable...
12
by: Alan | last post by:
Running PHP5 with IIS on a Win2K Server whenever I try file_exists() on a file in a windows share on another server I get a response of False - I can't open the file or do anything with it. I'm...
5
by: Ryan Liu | last post by:
Hi, Both way works, I'd just ask some experts which way is better? My application creates a log file daily. Now each time when I write a log, I will open the file and append to the end....
1
by: Carl | last post by:
In ASP.Net, how can we connect to a nas that uses cifs for its file sharing protocol. Currently we should be able to provide the ip address or hostname of the nas, the sharename along with any...
4
by: nightscorpion | last post by:
Hello Gurus, i implemented the OpenFileDialog in my Windows Form Applications and it worked perfectly fine.However when it was run on a remote desktop i got the below error . ...
18
by: Coffee Pot | last post by:
Thanks for any advice. ~ CP
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.