有段将MSMQ消息写入磁盘文件代码,如下:
****************************************
byte[] bytRecv = msg[i].Body;
FileInfo fi = new FileInfo(@recvDir + msg[i].Label);
FileStream fs = fi.Create();
fs.Write(bytRecv,0,bytRecv.Length);
fs.Close();
****************************************
当recvDir为"D:\InDir\"时运行正常,其中D盘为本地驱动器。但是如果为"H:\InDir"时出现错误,H盘为网络映射驱动器。执行到fi.Create(); 提示:“未找到路径:"H:\InDir\RecvFile.txt"的一部分”。难道不能直接操作网络驱动器吗?

解决方案 »

  1.   

    直接写\\IPAddress\X$\InDir 试试看.
      

  2.   

    FileInfo fi = new FileInfo(@"\172.26.18.100\D$\InDir\recvtest.txt");
    FileStream fs = fi.Create();
    这样也不行啊。
      

  3.   

    提示:{@"未找到路径“H:\NCIC\EDE\Inbound\201\aaa20060105120416.txt”的一部分。" }
      

  4.   

    因为是网络路径
    所以得先连接
    可以用cmd命令中的ping 和net use进行连接
    然后就像操作本地文件一样或者借助api
    WNetCancelConnection2
    WNetAddConnection2http://community.csdn.net/Expert/topic/3233/3233637.xml?temp=.5124323
    http://community.csdn.net/Expert/topic/4199/4199512.xml?temp=.0139429
      

  5.   

    各位前辈,在下发现一个奇怪的现象:
    同样的代码在控制台程序和windows服务程序的表现不一样。控制台程序运行正常,但是在windows服务程序中执行到FileStream fs2 = fi.Create()就报错。
    我想可能是MS的一个BUG!FileStream fs=new FileStream("D:\\Test.txt",FileMode.OpenOrCreate);
    byte[] byteArr = new byte[fs.Length];
    fs.Read(byteArr,0,Convert.ToInt32(fs.Length));
    fs.Close();
    FileInfo fi = new FileInfo(@"I:\Test.txt");    //  I为映射的网络驱动器
    FileStream fs2 = fi.Create();
    fs2.Write(byteArr,0,byteArr.Length);
    fs2.Close();
      

  6.   

    试试在你程序所在的站点添加一个虚拟目录指向你的映射的网络驱动器这个东西我先前做过,不过仅仅上面那样做的话只能读取,要写的话必须使用模拟用户<identity impersonate="true" userName="contoso\Jane" password="pass"/>
      

  7.   

    你在操作网络路径时,必须要登陆,要用net命令
    net use Z: \\201.101.0.1\D$ password user:administrator
    Z: \\201.101.0.1\D$为你影射的路径
    password为可以访问改网络路径的用户密码
    administrator为可以访问改网络路径的用户
      

  8.   

    我已经登陆过了,但是还是一样的.现在尝试用api:
    WNetCancelConnection2
    WNetAddConnection2
      

  9.   

    chenxingbai(单摆) ,你说的方法我还没有试,不知道怎么下手,能说的详细一点吗?
      

  10.   

    要写的话必须使用模拟用户?
    <identity impersonate="true" userName="contoso\Jane" password="pass"/>