我正在编写一个 ASP.NET (C#) 应用程序来为我的域创建用户。它还必须在单独的文件服务器上创建文件夹和共享。到目前为止,我已经能够使用
- System.IO.Directory.CreateDirectory 创建文件夹,
- a ("WinNT://fileserver/lanmanserver") DirectoryEntry 创建共享。
不幸的是,我的 ASP.NET 应用程序必须通过模拟运行才能创建文件夹。我不喜欢那样。我想知道是否有一种方法可以使用 DirectoryEntry 对象在文件服务器上创建文件夹,因为我可以将所需的凭据传递给它的构造函数。或者,有没有办法将凭据传递给 Directory.CreateDirectory?
提前致谢。这是当前代码,以防万一
strPath = "\\myServer\D$\newDir";
Directory.CreateDirectory(strPath);
using (DirectoryEntry deFS = new DirectoryEntry("WinNT://myServer/lanmanserver"))
{
using (DirectoryEntry deSH = deFS.Children.Add("newDir$", "fileshare"))
{
deSH.Properties["path"].Value = "D:\\newDir";
deSH.Properties["description"].Value = "My Stackoverflow sample share";
deSH.CommitChanges();
}
}