簡體   English   中英

訪問Visual Studio項目文件夾中保存的文件

[英]Accessing a file held within a project folder in Visual Studio

在Visual Studio中,我有一個文件,我想在我的一個類中訪問該文件。 該項目正在進行源代碼控制,因此我想使用相對路徑指向它在項目內部的位置。 我嘗試了以下總是返回DirectoryNotFoundException

filePPT = new PowerPointFile("~/IO/ExportTools/Template.pptx");

filePPT = new PowerPointFile("~\\IO\\ExportTools\\Template.pptx");

我的文件的位置具有以下結構:

在此處輸入圖片說明

如何在Visual Studio中使用相對路徑訪問文件?

將文件的“ CopyToOutputDir”屬性設置為“復制,如果較新”,以便將其復制到輸出文件夾中,然后創建相對於應用程序啟動路徑的路徑

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM