2013-12-20 135 views
0

我想使用的FileStream(C#)来读取共享文件夹中的文件在另一台电脑(窗口)如何通过C#从共享文件夹读取文件?

FileStream file = new FileStream(filePath, FileMode.Open); 

但 'System.IO.FileNotFoundException'

filePath = "\\sharefolder\test.csv" 
filePath = @"\\sharefolder\test.csv" 
filePath = "\\\\sharefolder\\test.csv" 

(这3种方式都FileNotFoundException异常)

我可以通过windows资源管理器访问该文件

+1

听起来像一个权限问题..或可能CAS。您是否在尝试运行VIsual Studio时以管理员身份进行测试? –

+0

您对'new FileStream'的调用使用名为'filePath'的变量,但其他三行代码使用名为'filaPath'的变量。您可能想要[编辑]并通过用您尝试的**实际变量和内容替换它们来修复它们;当你为自己的问题编写东西时,它经常隐藏真正的问题。 –

+0

有点小错,“\\\\ sharefolder \\ test.csv”现在就可以运行。 – Sam

回答

0

一般情况下,你会设置这些项目将被复制到bin文件夹。右键点击solution explorer/navigator,选择properties并将Copy to output directory设置为不同。

DirectoryInfo diSrc = new DirectoryInfo(@"\\Ip_Address_OfComputer\D(D or c Directory)\Shared folder"); 
DirectoryInfo diDest = new DirectoryInfo(@"D:\New folder at your machine"); 
CopyDirectory(diSrc, diDest, "174"); 

然后您可以阅读该文件。

相关问题