简体   繁体   English

访问Visual Studio项目文件夹中保存的文件

[英]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.

相关问题 如何从Visual Studio中的项目/服务器文件夹中获取文件名? - how to get file names from project/server folder in visual studio? 如何从 Visual Studio 项目中排除文件/文件夹? - How to exclude file/folder from visual studio project? 如何在Visual Studio解决方案的项目中检查文件是否存在于文件夹中 - How to check if file exists in a folder in my project in Visual Studio solution Visual Studio在WinForms项目文件夹中创建的文件类型是什么? - What are these file types that Visual Studio is creating in a WinForms project folder? 更改Visual Studio 2015扩展中项目中文件ProjectItem的内容吗? - Change the contents of a file ProjectItem within a Project in a Visual Studio 2015 Extension? Visual Studio 文件夹文件路径 - Visual Studio Folder file path 如何在Visual Studio 2010中的项目文件夹中访问bin / debug中的文件? - How to access the files in bin/debug within the project folder in Visual studio 2010? 在Visual Studio模板中更改项目文件夹路径 - Change Project Folder Path in Visual Studio Template 有没有办法在Visual Studio 2012中将文件夹转换为项目? - Is there a way to convert a folder to a project in Visual Studio 2012? Visual Studio 2015未显示项目文件夹内容 - Visual Studio 2015 not showing project folder content
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM