[英]Accessing a file held within a project folder in Visual Studio
Within Visual Studio I have got a file which I would like to get access to in one of my classes. 在Visual Studio中,我有一个文件,我想在我的一个类中访问该文件。 This project is going onto source control so I'd like to use a relative path which points to where it is located inside the project.
该项目正在进行源代码控制,因此我想使用相对路径指向它在项目内部的位置。 I've tried the following which always returns a
DirectoryNotFoundException
: 我尝试了以下总是返回
DirectoryNotFoundException
:
filePPT = new PowerPointFile("~/IO/ExportTools/Template.pptx");
And 和
filePPT = new PowerPointFile("~\\IO\\ExportTools\\Template.pptx");
The location of my file is in the following structure: 我的文件的位置具有以下结构:
How can I access the file within Visual Studio using a relative path? 如何在Visual Studio中使用相对路径访问文件?
将文件的“ CopyToOutputDir”属性设置为“复制,如果较新”,以便将其复制到输出文件夹中,然后创建相对于应用程序启动路径的路径
filePPT = new PowerPointFile(Path.Combine(Application.StartupPath, "IO/ExportTools/Template.pptx"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.