How do I map a network drive that requires a username and password in .NET?

前端 未结 2 1884
情歌与酒
情歌与酒 2020-12-09 12:27

I need to map a network drive from within a .NET application. I\'m going to need to use an AD Username and Password to authenticate. Usually I just use a batch file with t

2条回答
  •  心在旅途
    2020-12-09 12:56

    Have you looked at this?

    http://www.codeguru.com/csharp/csharp/cs_network/windowsservices/article.php/c12357

    Also, you could just use net.exe via Process.Start() and pass it the parameters you've always used in the code below:

    System.Diagnostics.Process.Start("net.exe", "use K: \\\\Server\\URI\\path\\here");
    

    This can also be used without a drive letter and then accessed through the UNC path.

     System.Diagnostics.Process.Start("net.exe", @"use @"\\Server\URI\path\here");
     System.IO.File.Copy(@"\\Server\URI\path\here\somefile.abc", destFile, true);
    

提交回复
热议问题