如何通过C#从共享文件夹中读取文件?

时间:2013-12-20 03:12:00

标签: c# .net file file-io

我想使用FileStream(C#)读取另一台PC(windows)中共享文件夹中的文件

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 个答案:

答案 0 :(得分: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");

然后你可以阅读该文件。