Solved

How can I access a network share using userid / password in code

Posted on 2014-09-15
8
930 Views
Last Modified: 2014-10-01
I tried some open source that I found

  using (NetworkShareAccesser.Access("remoteComputername", "domain", "userid", "passoword"))
                        {
                            if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); }
                        }

But this gives me an error - network name not found
0
Comment
Question by:countrymeister
  • 4
  • 4
8 Comments
 
LVL 26

Expert Comment

by:pony10us
ID: 40323440
Did you also get the code for "NetworkShareAccesser"?
0
 
LVL 1

Author Comment

by:countrymeister
ID: 40323514
Yes, of course, How else would my code compile and I would be able to debug and get that error
0
 
LVL 26

Expert Comment

by:pony10us
ID: 40323607
I would verify you have all the correct variables set in the "NetworkShareAccesser" code.  The error you are getting indicates that it can't find the remote computer.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 1

Author Comment

by:countrymeister
ID: 40323707
I will try and do that, but do you have a solution to access a network share using a userid password.
0
 
LVL 26

Expert Comment

by:pony10us
ID: 40324165
I usually do it with Net Use:

net use \\server\share /user:name password

If you want to access the share afterwards:

start \\server\share

So you could save this as a batch file:

@echo off
net use \\server\share /user:name password
start \\server\share

Remember to use quotes around the name and/or password if they contain blanks.
0
 
LVL 1

Author Comment

by:countrymeister
ID: 40333358
Pony itried Net use , but it does not work, because I have subdirectories and cannot get to the sub directories
0
 
LVL 26

Accepted Solution

by:
pony10us earned 500 total points
ID: 40333471
Is this just a snippet of code for a larger project?  

Using what I provided would simply open the share in a window. This should allow you to access anything in the share.

If you are attempting to use this as a snippet of a larger piece of code to run unattended then you are correct that as written it will not work.

What you would need is to assign it a drive letter and access it using that letter.

For example:

net use z: \\server\share /user:name password
copy z:\subfolder\file.ext c:\folder
net use z: /delete

Open in new window


Would map the share to z: using the credentials provided, copy a file from the subfolder in the share to a folder on the C: drive and finally disconnect the Z: drive.

Is this closer to what you are wanting?
0
 
LVL 1

Author Closing Comment

by:countrymeister
ID: 40354705
I had to change some of the Network Accessor code and got it to work. Cannot use net use in line project
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 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