1

I have been using Url.Content inside <% and %> in my views and all seems to be working fine... Then from withing my controller i have tried the following, but it always returns the wrong path

 XDocument xdoc = XDocument.Load(Url.Content("~/content/xml/faq.xml"));

and

 XDocument xdoc = XDocument.Load(VirtualPathUtility.ToAbsolute("~/content/xml/faq.xml"));

Basically the path shoudl be c:\Vs2008\Source\MyAppName.....

but its returning c:\MyAppName.....

So its invalid,

Any ideas why this is happning?? Is there a work around?

3 Answers 3

5

Those two methods are only meant to be used in the context of clients accessing content through your web server. To read a file internally, within the application you need to use Server.MapPath() or a similar method to get the physical path on your disk.

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

Comments

2

That's correct. I'm not sure why it's adding the C:\ but MyApp...\ is the absolute path.

Have you tried Server.MapPath?

Comments

1

I was having a similar problem linking to some .css and image files. I wrote a blog post on this at http://www.stickfiguresoftware.com/node/46 that may be helpful and even has some sample code that I got to work.

Not sure it's the perfect solution, but it worked out for me.

Comments

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.