Solved

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

Posted on 2014-09-15
8
980 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 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