![](/img/trans.png)
[英]MS Visual Studio - how to import a project or solution from file system and know what kind of project it is
[英]How to read file from Visual Studio solution/project?
FileInfo template = new FileInfo(@"C:\Users\bryan\Desktop\ReportTemplate.xlsx");
template.IsReadOnly = false;
這很適合測試,但我的項目解決方案中有 ReportTemplate.xlsx。 我如何使用該文件而不是桌面上的本地文件? 如何引用解決方案中的文件?
你想使用Server.MapPath();
確保你想要的文件已經添加到項目中:File->Add Existing
FileInfo template = new FileInfo(Server.MapPath("~/Directory/ReportTemplate.xlsx");
template.IsReadOnly = false;
~
代表項目的“根”。
我認為這只適用於 ASP.NET。
這取決於解決方案中文件的位置。 主文件夾是您構建的項目文件夾中的 \bin\debug。 如果要引用項目文件夾根目錄中的文件,請使用“..\..\yourfilename.xlsx”
文件屬性->復制到Output目錄
然后您可以使用“ReportTemplate.xlsx”訪問它
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.