We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose 8.5.2- Will not open workbook

I have the latest dll and we’ve having a problem with the Workbook wb = new Workbook(fileName); method. No matter what you put in for the file name, you get a DirectoryNotFoundException error because it keeps looking in the wrong directory.

I fill the fileName variable with "%UserProfile%\Downloads\Project Portfolio.xlsx"
and it looks in

"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE%UserProfile%\Downloads\Project Portfolio.xlsx"

I have no idea where it’s getting “C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE” from.

What am I missing? Any ideas?

Hi Craig,

Thank you for contacting Aspose support.

First of all, please note that the string %UserProfile% points to a relative location, that is; user home therefore when you pass only the string “%UserProfile%\Downloads\sample.xlsx” to Workbook (or even FileStream) object, the application tries to convert it to absolute path depending upon the application type. For instance, the Console type application converts the path by pre-appending the absolute path to \bin\Debug\ folder such as “C:\Users\Babar Raza\Documents\Visual Studio 2013\Projects\Cells\Cells\bin\Debug%UserProfile%\Downloads\sample.xlsx” where the specified folder does not exist so the application throws the appropriate exception.

Further more, the presented scenario has no relevance to Aspose.Cells for .NET APIs as you will not be able to load the file in an instance of FileStream as well. Please try the following piece of code.


var file = new FileStream(@"%UserProfile%\Downloads[File Name]", FileMode.Open);

I am having a similar issue, every time i try to pass in a relative reference (not using filestream) aspose appears to be adding the directory to my iis. is there a way to pass in something similar to @"~\content\template.xlsx" so that my new workbook will look for the template file in my project?

Hi Anthony,

First of all, the scenario discussed in your post is quite different from what has been discussed in this thread. If you wish to load a spreadsheet from a folder present in the project directory, you can do it as follow.


var path = System.Web.Hosting.HostingEnvironment.MapPath("~");
var pathToFile = path + @“templates\sample.xlsx”;
var book = new Workbook(pathToFile);