2011-08-18 186 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将为您获取它。 –

相关问题