How to connect to Share-Drive using Simple Impersonation Nuget package with C#?

Today, I gonna show u how we can connect the Share Drive using Simple Impersonation C# plugin. First, we need to install the Nuget package to your C# Project.

PM> Install-Package SimpleImpersonation -Version 3.0.0

var credentials = new UserCredentials(".", "<username>", "<password>");
Impersonation.RunAsUser(credentials, LogonType.NewCredentials, () =>
DirectoryInfo directory = new DirectoryInfo(@"\\<share-path>\<share-folder>");
//Get Directory List
DirectoryInfo[] directoryList = directory.GetDirectories();
for (int i = 0; i < directoryList.Length; i++)

//Get File List
FileInfo[] fileList = directory.GetFiles();
for (int i = 0; i < fileList.Length; i++)

That’s it. I hope this will help. 🙂

17 Replies to “How to connect to Share-Drive using Simple Impersonation Nuget package with C#?”

  1. It’s a pity you don’t have a donate button! I’d without a doubt donate to this
    superb blog! I suppose for now i’ll settle for book-marking and adding your RSS feed to my Google account.
    I look forward to fresh updates and will share this website with
    my Facebook group. Talk soon!

  2. I was curious if you ever thought of changing the structure of
    your blog? Its very well written; I love what youve got to say.

    But maybe you could a little more in the way of content so people could connect with it
    better. Youve got an awful lot of text for only having 1 or two pictures.
    Maybe you could space it out better?

  3. Der Artikel ist wirklich gut. Das Thema hat mich schon sehr lange interessiert und ich konnte hier noch
    einiges weiterführendes finden. Ich freue mich,
    weitere Neuigkeiten zu lesen. Danke und Grüße aus Heidelberg Marco Feindler

  4. excellent ѕubmit, very informative. I ԝonder why the other experts of this sector
    don’t understand thiѕ. Yօu must proceed your writing.
    I am sure, you’ve а great readerѕ’ bаse already!

  5. This is very fascinating, You’re an overly skilled blogger.
    I have joined your feed and stay up for in search of more of your excellent post.
    Additionally, I have shared your site in my social networks

  6. I blog frequently and I genuinely appreciate your content.
    This article has truly peaked my interest. I am going to book mark your blog
    and keep checking for new information about once per week.
    I opted in for your RSS feed as well.

Leave a Reply

Your email address will not be published. Required fields are marked *