简体   繁体   中英

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. 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 :

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?

将文件的“ CopyToOutputDir”属性设置为“复制,如果较新”,以便将其复制到输出文件夹中,然后创建相对于应用程序启动路径的路径

filePPT = new PowerPointFile(Path.Combine(Application.StartupPath, "IO/ExportTools/Template.pptx")); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM