您的位置:首页 > 其它

建立共享文件夹连接

2005-01-05 17:10 281 查看
[StructLayout(LayoutKind.Sequential)] <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

       class NETRESOURCE

{

       public int dwScope;

       public int dwType;

       public int dwDisplayType;

       public int dwUsage;

       public string LocalName = null;

       public string RemoteName = null;

       public string Comment = null;

       public string Provider = null;

}

[DllImport("mpr.dll")]       

private static extern int WNetAddConnection2(NETRESOURCE netResource, string password, string username, int flags);

 

private void EstablishConnection()

{

       NETRESOURCE netResource = new NETRESOURCE();

       netResource.dwScope = 2;

       netResource.dwType = 1;

       netResource.dwDisplayType = 3;

       netResource.dwUsage = 1;

       netResource.RemoteName = @"//192.168.108.18/fbfilestorage";

       int ret = WNetAddConnection2(netResource, "password", @"machinename/username", 0);           //the ret value in ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/debug/base/system_error_codes.htm

 

       if (ret != 0)

       {

              throw new Exception(string.Format("Failed to connect the shared folder:{0}", this.workingFolder));

       }

      

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  string null exception class
相关文章推荐