File.ReadAllLines在webservice上不起作用

use*_*618 2 c# web-services

我想读取txt文件中的所有行,我使用它来File.ReadAllLines.

在winforms它工作正常.

但是,当我'尝试在webmethod的webservice上做同样的事情时它会崩溃

System.IO.FileNotFoundException:Niemożnodnnaleźćpliku'C:\ Program Files\Microsoft Visual Studio 9.0\Common7\IDE \nameOfFile.txt'.

CopyOutputToDirectory设置为始终复制.

  string[] lines = File.ReadAllLines("nameOfFIle.txt", Encoding.Default)
Run Code Online (Sandbox Code Playgroud)

文件位于webservice的webservice文件夹中,以及应用程序的应用程序文件夹中

Dar*_*rov 5

如果web.config文件位于Web服务的根文件夹(文件所在的位置),则需要获取Web服务根路径并将其与文件名组合:

var path = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "nameOfFile.txt");
string[] lines = File.ReadAllLines(path, Encoding.Default);
Run Code Online (Sandbox Code Playgroud)