HttpContext.Current
does not work outside of a web context.
If your project is running inside a console or windows program, it cannot work with HttpContext.Current
. MapPath
is meant to translate a web path to a file system path. ~/
is a .Net convention for pointing the root web path of a web application.
You should explicit what are your requirements about how to resolve the folder containing your file.
Maybe should you simply put that in some configuration file (using settings property tab of the project by example) and retrieve it from there.
Edit:
So, from your comment on this question, it looks like you have to seek the xl file in the executing folder.
There is a number of ways for achieving this, depending on your application use cases.
By example, check this question.
Document/Visual Studio 2013/Project/ProjectName
is the root of a web projet; 2 - your code snippet is executed in the context of this web project responding to a http request; 3 - what is the code which does fail? Presumably something trying to openpath
, but it is lacking in your code snippet; 4 - have you tried to inspectpath
local variable value? – Milinda