往网络共享文件夹里 发送文件

loran 2009-04-21 04:43:57
RT

网络文件夹下有账号密码的情况下 怎么传,
...全文
96 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
loran 2009-04-24
  • 打赏
  • 举报
回复
自己解决掉了,但是还是感谢,

秋枫的方法是正确的

当时也找的是这个方法,但是几次试验都不成功,

后来找到原因 是因为加入到域中,判断共享文件夹权限的时候会首先用域账号信息去匹配,如果不成功则直接返回错误信息,

这个用 net use 指令就能试验,(另外Server2008试验的话,就算是用域账号也能通过net use方式打开网络共享目录,应该是2008系统进行了某些方面的优化吧)
marvelstack 2009-04-21
  • 打赏
  • 举报
回复
public static class WNetConnectionHelper
{
[DllImport("mpr.dll", EntryPoint = "WNetAddConnection2")]
private static extern uint WNetAddConnection2(NetResource lpNetResource, string lpPassword, string lpUsername, uint dwFlags);

[DllImport("Mpr.dll", EntryPoint = "WNetCancelConnection2"))]
private static extern uint WNetCancelConnection2(string lpName, uint dwFlags, bool fForce);

[StructLayout(LayoutKind.Sequential)]
public class NetResource
{
public int dwScope;
public int dwType;
public int dwDisplayType;
public int dwUsage;
public string lpLocalName;
public string lpRemoteName;
public string lpComment;
public string lpProvider;
}

public static uint WNetAddConnection(NetResource netResource,string username,string password)
{
uint result = WNetAddConnection2(netResource, password, username, 0);
return result;
}

public static uint WNetAddConnection(string username, string password, string remoteName, string localName)
{
NetResource netResource = new NetResource();
netResource.dwScope = 2; //RESOURCE_GLOBALNET
netResource.dwType = 1; //RESOURCETYPE_ANY
netResource.dwDisplayType = 3; //RESOURCEDISPLAYTYPE_GENERIC
netResource.dwUsage = 1; //RESOURCEUSAGE_CONNECTABLE
netResource.lpLocalName = localName;
netResource.lpRemoteName = remoteName.TrimEnd('\\');
//netResource.lpRemoteName = lpComment;
//netResource.lpProvider = null;
uint result = WNetAddConnection2(netResource, password, username, 0);
return result;
}

public static uint WNetCancelConnection(string name,uint flags,bool force)
{
uint nret = WNetCancelConnection2(name, flags, force);
return nret;
}
}
marvelstack 2009-04-21
  • 打赏
  • 举报
回复
可以通过调用WNetAddConnection2 API来实现,写了一个WNetConnectionHelper辅助类,楼主可以看下面的文章,获得完整的代码例子。
http://blog.csdn.net/zhzuo/archive/2007/08/08/1732937.aspx
快40的码农 2009-04-21
  • 打赏
  • 举报
回复
ftp
ouyangyanyue 2009-04-21
  • 打赏
  • 举报
回复
不知道用OpenRead方法打开网络上的数据流对不对哈,你是传还是下?
jxph123535 2009-04-21
  • 打赏
  • 举报
回复
FileStream 吧

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧