2011-08-18 188 views
2
FileInfo template = new FileInfo(@"C:\Users\bryan\Desktop\ReportTemplate.xlsx"); 
template.IsReadOnly = false; 

這對測試很不錯,但我的項目解決方案中有ReportTemplate.xlsx。我如何在桌面上使用該文件而不是本地文件?如何在解決方案中引用文件?如何從Visual Studio解決方案/項目中讀取文件?

回答

0

這取決於解決方案中的文件所在的位置。主文件夾是您構建的項目文件夾中的\ bin \ debug。如果要引用這是根,你的項目文件夾使用的文件「.. \ .. \ yourfilename.xlsx」

2

你想用Server.MapPath();

確保你想要的文件已經被添加該項目:文件 - >添加現有

FileInfo template = new FileInfo(Server.MapPath("~/Directory/ReportTemplate.xlsx"); 
template.IsReadOnly = false; 

~表示項目的「根」。

我認爲這隻適用於ASP.NET。

+0

這是一個網絡應用程序。 – SplatXX3

+0

然後Server.MapPath是你想要的。將該文件放在應用程序的根目錄或任何目錄中,Server.MapPath將爲您獲取它。 –

相關問題