C# open file on windows share

Discussion in 'ASP .Net' started by P4trykx, Aug 7, 2007.

  1. P4trykx

    P4trykx Guest

    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
    P4trykx, Aug 7, 2007
    #1
    1. Advertising

  2. P4trykx

    Andrew Brook Guest

    does this work?
    System.IO.FileStream fs = new
    System.IO.FileStream(serverFilePath,System.IO.FileMode.Open,System.IO.FileAccess.Read);

    Andrew

    "P4trykx" <> wrote in message
    news:...
    > 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
    >
    Andrew Brook, Aug 7, 2007
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > 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
    >
    Kevin Spencer, Aug 7, 2007
    #3
  4. P4trykx

    P4trykx Guest

    On 7 Sie, 13:00, "Andrew Brook" <> wrote:
    > does this work?
    > System.IO.FileStream fs = new
    > System.IO.FileStream(serverFilePath,System.IO.FileMode.Open,System.IO.FileA­ccess.Read);


    no, I get the same Exception


    --
    Patryk
    P4trykx, Aug 7, 2007
    #4
  5. P4trykx

    P4trykx Guest

    On 7 Sie, 13:35, "Kevin Spencer" <> 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
    P4trykx, Aug 7, 2007
    #5
  6. P4trykx

    Aidy Guest

    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" <> wrote in message
    news:...
    > On 7 Sie, 13:35, "Kevin Spencer" <> 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
    >
    Aidy, Aug 7, 2007
    #6
  7. P4trykx

    P4trykx Guest

    On 7 Sie, 15:18, "Aidy" <> 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
    P4trykx, Aug 7, 2007
    #7
  8. 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" <> wrote in message
    news:...
    > On 7 Sie, 15:18, "Aidy" <> 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
    >
    >
    >
    >
    Kevin Spencer, Aug 8, 2007
    #8
  9. P4trykx

    P4trykx Guest

    On 8 Sie, 13:08, "Kevin Spencer" <> 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
    P4trykx, Aug 8, 2007
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad
    Replies:
    4
    Views:
    462
    tshad
    Nov 1, 2009
  2. Saraswati lakki
    Replies:
    0
    Views:
    1,298
    Saraswati lakki
    Jan 6, 2012
  3. Jack
    Replies:
    2
    Views:
    204
  4. Kory Woods
    Replies:
    7
    Views:
    123
    Kory Woods
    Jul 14, 2008
  5. Eric Wong
    Replies:
    0
    Views:
    195
    Eric Wong
    Feb 13, 2010
Loading...

Share This Page