![](/img/trans.png)
[英]How to copy file from network path to local location with WCF Webservice?
[英]Copy file to remote location throws network path not found intermittently
我正在尝试将我的c#代码生成的文件(Excel文件)复制到我可以访问的远程网络路径中,如下所示:
string folder = "\\\\testing-path\\Audit\\Reports";
if (!(Directory.Exists(folder + "\\" + DateTime.Now.ToString("MM-dd-yyyy") + "\\" + "Audit")))
{
Directory.CreateDirectory(folder + "\\" + DateTime.Now.ToString("MM-dd-yyyy") + "\\" + "Audit");
}
folder = folder + "\\" + DateTime.Now.ToString("MM-dd-yyyy") + "\\" + "Audit";
if (File.Exists(folder + "\\Audit- " + fname + ".xlsx"))
{
File.Delete(folder + "\\Audit- " + fname + ".xlsx");
}
string fileName = folder + "\\Audit- " + fname + ".xlsx";
wb.SaveAs(fileName,
Excel.XlFileFormat.xlWorkbookDefault, null, null,
false, false, Excel.XlSaveAsAccessMode.xlNoChange,
null, null, null, null, null);
此代码完美地工作8/10次,并抛出网络错误(未找到网络路径)2次。 当远程路径抛出此错误时,我在运行此代码的计算机上使用run命令打开上面的远程路径,我可以正常访问它。 关闭手动打开的文件夹并重新运行代码正在解决问题。 可能是什么问题? 我在这里做错了吗?
PS:我还试图将excel文件保存到桌面上,然后使用File.Copy
,这种间歇性行为没有变化。
检查以下事项
1) First you have to check whether machine is on or off
2) Then check you have access rights to put the file in that particular folder and dont
put it inside ' C ' Drive because C is not accessible for other users in network put it inside D or E drive.
3) If Folder is Missing You have to Create A Folder first
什么是'WB'
if(!Directory.Exists("\\\\testing-path\\Audit\\Reports"))
Directory.Create("\\\\testing-path\\Audit\\Reports");
采用
FilePath Byte
File.ReadAllBytes("FilePath/FileName.Extension",byte) // D:\\Test.xls,12878
然后在远程位置FilePath字节
File.WriteAllBytes("FilePath/FileName.Extension",byte)// D:\\Test123.xls,12878
检查此链接
访问远程计算机中的路径: http : //www.codeproject.com/Questions/184633/Connect-to-a-shared-folder-using-ip-address-in-vb6
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.