How to get the Absolute Path of a File on Server

If you are trying to access a file on Server and you need Absolute Path of that file you can use Server.MapPath method that takes a virtual path as its argument and returns the corresponding physical or absolute path.

To get physical path of a file located on root of your website

string path = Server.MapPath("products.xml");


string path = Server.MapPath(".") + "\\products.xml";

To get physical path of a file located in a sub directory such as data of your website.

string path = Server.MapPath("data") + "\\products.xml";



About author

User avatar

Waqas Anwar

Founder of, Senior Consultant, Microsoft .NET and Web Technologies