Authentication using the NetworkCredential class in .Net

Posted on 2009-02-14
Last Modified: 2013-12-17

I'm trying to write an application that reads files off a network share.  The problem is that the domain requires authentication before the application may access the share.  I'm trying to use the NetworkCredential class to automate this.  I have the appropriate username and password.

Please assist me in using the Network Credential class to achieve this.

I have attached some code


'Dim NetC As New System.Net.NetworkCredential


        'NetC.Domain = "PRODDOM"

        'NetC.UserName = "admin-s1038920"

        'NetC.Password = "YY9hJ90!hH$"



         --This prompts for username and password

        Chart1.SaveImage(My.Settings.ImageTargetPath & My.Settings.SaveToImageName, _


Open in new window

Question by:PantoffelSlippers

    Author Comment

    LVL 96

    Expert Comment

    by:Bob Learned
    Are you talking about impersonation?

    Author Comment


    To be honest with you:  I don't know.

    I basically don't know what could be a solution for me.

    All I'm looking to do is programmtically access a shared folder.

    If authentication is required then my code needs to provide it automatically.

    If impersonation can help me achieve that then yes, we can have a look at impersonation.

    I've just read a couple of articles on impersonation and it seems as if it could be what I'm looking for!
    LVL 96

    Accepted Solution

    There are plenty of examples that use impersonation to access a network share.

    Here is a C# CodeProject article:

    Windows Impersonation using C#


    Author Comment

    Thank you TheLearnedOne,

    I was unfamiliar with Impersonation up until now.

    Well, I still am but at least now I know about it.

    I'll check out the link  - maybe it'll solve my problem.

    Post back soon


    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now