问题描述
web程序中映射网络驱动器一直返回2202求助到底哪里出了问题
解决方案
解决方案二:
usingSystem.Runtime.InteropServices;usingSystem.IO;usingSystem;publicclassWNetHelper{[DllImport("mpr.dll",EntryPoint="WNetAddConnection2")]privatestaticexternuintWNetAddConnection2(NetResourcelpNetResource,stringlpPassword,stringlpUsername,uintdwFlags);[DllImport("Mpr.dll",EntryPoint="WNetCancelConnection2")]privatestaticexternuintWNetCancelConnection2(stringlpName,uintdwFlags,boolfForce);[StructLayout(LayoutKind.Sequential)]publicclassNetResource{publicintdwScope;publicintdwType;publicintdwDisplayType;publicintdwUsage;publicstringlpLocalName;publicstringlpRemoteName;publicstringlpComment;publicstringlpProvider;}///<summary>///为网络共享做本地映射///</summary>///<paramname="username">访问用户名</param>///<paramname="password">访问用户密码</param>///<paramname="remoteName">网络共享路径</param>///<paramname="localName">本地映射盘符</param>///<returns></returns>publicstaticuintWNetAddConnection(stringusername,stringpassword,stringremoteName,stringlocalName){NetResourcenetResource=newNetResource();netResource.dwScope=2;netResource.dwType=1;netResource.dwDisplayType=3;netResource.dwUsage=1;netResource.lpLocalName=localName;netResource.lpRemoteName=remoteName.TrimEnd('/');uintresult=WNetAddConnection2(netResource,password,username,0);returnresult;}publicstaticuintWNetCancelConnection(stringname,uintflags,boolforce){uintnret=WNetCancelConnection2(name,flags,force);returnnret;}publicstaticboolCreateDirectory(stringpath){//LogonImpersonateimper=newLogonImpersonate("administrator","1234");uintstate=0;if(!Directory.Exists("Z:")){state=WNetHelper.WNetAddConnection("LIJIELUN//administrator","1234",@"//10.36.0.122/yedmis_file","Z:");}if(state.Equals(0)){Directory.CreateDirectory(path);returntrue;}else{thrownewException("添加网络驱动器错误,错误号:"+state.ToString());}}
附一下源码