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.