C# WCF Server 应用程序 - 访问服务器上的文件相对
我有 ac# 服务器应用程序(WCF),并且我在该服务器上保存了一个文件,我想相对地访问它,以便每个开发机器都可以使用它。
这是文件路径。
C:\Users\ben\Documents\Visual Studio 2010\Projects\ myfile.xml
我想要从中访问文件的项目位于:
C:\Users\ben\Documents\Visual Studio 2010\Projects\ MyProject
访问 myfile.xml (相对)的最佳方式是什么?来自我的项目?
I have a c# server application (WCF) and I have a file saved on that server and i want to access it relatively so every dev machine can work with it.
this is the file path.
C:\Users\ben\Documents\Visual Studio 2010\Projects\ myfile.xml
the project where i want to access the file from is in:
C:\Users\ben\Documents\Visual Studio 2010\Projects\ MyProject
what is the best way to access the myfile.xml (relatively)? from MyProject?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,当您运行该项目时,您的当前目录将类似于:
C:\Users\ben\Documents\Visual Studio 2010\Projects\MyProject\MyProject\bin\Debug\
所以您可能会想做点别的事。
将该文件包含在项目中,然后转到该文件的“文件属性”。为
复制到输出目录
设置选择始终复制
。然后,在编译/构建时,该文件将被复制到与 EXE 相同的目录中。这样您只需通过文件名即可访问该文件。Well, when you run the project, your current directory will be something like:
C:\Users\ben\Documents\Visual Studio 2010\Projects\MyProject\MyProject\bin\Debug\
So you will probably want to do something else.
Include the file in the project and go to File Properties for the file. Select
Copy Always
for theCopy to Output Directory
setting. The file will then be copied to the same directory as the EXE when compiling/building. That way you can access the file simply by its filename.从您的问题来看,我们的理解是您想要访问您的项目位置,而不需要可执行文件和文件夹。为此,请尝试以下代码:
From your question , what is under stood is that you want to access your project location , without the executable file and folder . To do that try the following code :