Get full file path c# web app

I have a dotx file un my Web PAge, I created a folder called "Templates" (all inside my Vs project)  and I added this file inside.

I would like to get the full path with code in order to dont worry about paths when I publish the page.

I have tried code like

string path = Server.MapPath("file.dotx");
System.IO.FileInfo file = new System.IO.FileInfo(path);

but it doesn work because it gives me a wrong folder.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It seems like you would need to put:

string path = Server.MapPath("Templates\file.dotx");
Kyle AbrahamsSenior .Net DeveloperCommented:
In general I like always starting from the root:



the tilda (~) says go to root of the web directory.
VeljeanAuthor Commented:
I dont get it... it gives me a extra folder:

C:\Documents and Settings\DIGEVCE\Mis documentos\Visual Studio 2010\WebSites\ModuloProgramacion\Formularios\Plantillas\CCE_42_Gen_2011_1.dotx

when physically my file is in

C:\Documents and Settings\DIGEVCE\Mis documentos\Visual Studio 2010\WebSites\ModuloProgramacion\Plantillas\CCE_42_Gen_2011_1.dotx
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Kyle AbrahamsSenior .Net DeveloperCommented:
if your page is in Formularios then you would need to use the ~ to get back up to the root.



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VeljeanAuthor Commented:
thanks ged325 , Im not very sure how it works but thanks anyway!!
Kyle AbrahamsSenior .Net DeveloperCommented:
Your file was most likely in a different directory.



by default yourfile.aspx looks in otherDIR and any folders underneath it.

So if you had

yourfile.Aspx could access it via Server.MapPath(childDir + "\" + <file>)

However in your case you wanted to go one level up:


Correct path is ("..\SomeDir\File.dotx")

But if you change the directory structure then you have to worry about all the links.  The best way to do this is using the tilda:  "~"

tilda means go to AppRoot.

so in this sense "~" == "c:\inetpub\wwwroot\AppRoot"

then from there you can just apply the directories as needed.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.