1

In My project ,i have a folder with Details.aspx page. and i have Details.xml file outside of the folder. Now i want to get file location of Details.xml to Details.aspx.cs page. i have tried different ways, but i am not getting file location.

Details.aspx.cs :

 private void GenerateXMLFile()
    {
        try
        {
            DataSet dsJobsDetails = new DataSet();
            dsJobsDetails = GetJobDetails();               
            string fileLoc = Server.MapPath("Details.xml"); 

            if (File.Exists(fileLoc))
            {
                try
                {
                    dsJobsDetails.WriteXml(fileLoc);
                    Response.Redirect("Details.xml");
                }
                catch { }
            }
        }
        catch { }
    }

Please tell me how to get file location. Thank you..

2 Answers 2

2
string fileLoc = Server.MapPath("~/Details.xml");

Will give you the full path to the Details.xml file on your server, something like C:\inetpub\wwwroot\application\Details.xml.

You can return that as URL by redirecting to it for example, using ~/ (the application root, in URL form):

Response.Redirect("~/Details.xml");

This will translate into a redirect to something like http://server/Application/Details.xml.

Sign up to request clarification or add additional context in comments.

Comments

2

For example your file structure is like this

/Details.aspx.cs
/MyFolder/Details.xml

Then you can get the file location by this

string fileLoc = Server.MapPath("/MyFolder/Details.xml");

1 Comment

My .xml file is located outside of the folder i,e /Details.xml and .cs file in folder ie. /MyFolder/Details.aspx.cs..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.