I am using the C# code below to get the url to an xml file. The current page is News.aspx and the XML file is in the same folder, which is why this works fine.
xUrl = Request.Url.GetLeftPart(UriPartial.Path).Replace("News.aspx", "news.xml");
But it feels a little wrong to me, what if News.aspx changed? Is this the right way to do this sort of thing? Or is there a better way to get the URL of a file?
Thanks
I would use
Server.MapPathto get the URL of a file.you can then get this in your code
You could add http://www.donetnukelabs‘ suggested answer and pop the name of your xml file into a settings store (web config perhaps), if it’s likely to change.