This project has moved. For the latest updates, please go here.

Error: invalid templatepath on server

Jan 18, 2012 at 8:32 PM

My code is simple, it just opens an existing file using UNC path, modifies one cell and saves the file.  When I run the code locally, it works fine. When I move this code to a company server and run it, I get an error: invalid templatepath.

FileInfo template1 = new FileInfo("\\\\serverxyz\\Temp\\createbatch.xlsx");

using (ExcelPackage p1 = new ExcelPackage(template1, true))  {


The account the webserver code uses to access the folder above has full control permissions on the folder.

I also tried:

FileInfo template1 = new FileInfo(@"\\serverxyz\Temp\createbatch.xlsx");


Any ideas?  Thanks.

Jan 31, 2012 at 6:53 PM

If you havn't solved this already, try to read the file as byte array and open it in a memory stream to see if you can read the file into memory.


Mar 30, 2012 at 3:44 PM


Were you able to solve this issue ?

I'm having exactly the same problem although I'm using:
FileInfo template = new FileInfo(Directory.GetCurrentDirectory() + "myfile.xlsx"); [I'm running it locally]

I'm working with C# for a week now, can you help on "reading the file as byte array and open it in a memory stream" ?  

Apr 15, 2013 at 2:19 PM
you can solve this issue by changing the package statement to the following
using (ExcelPackage p = new ExcelPackage(new MemoryStream(), new MemoryStream(File.ReadAllBytes(System.Web.HttpContext.Current.Server.MapPath("Test.xlsx")))))
I found this via