In my ASP.NET MVC application, I create excel reports, I have a template file that I copy and modify. This template file is placed in a folder in my solution. I want to use it as follows:
string templatePath = @"\Templates\report.xlsx";
using (var template = File.OpenRead(templatePath)) {
}
But this code throws an exception
Couldnot find a part of the path 'C:\Templates\report.xlsx'.
How do I access this file?
I also tried using
string templatePath = @"~\Templates\report.xlsx";
But this leads to
Could not find a part of the path 'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\~\Templates\report.xlsx'.
However, it works when I use the absolute path, but it does not make sense for my production server.
source
share