Eric J.
Eric J.

Reputation: 150108

MVC 3 VirtualPathUtility Issue

I have an MVC 3 app with a Configuration folder that holds XML files specific to my application. I'm trying to enumerate the files in a view like this:

string configPath = VirtualPathUtility.ToAbsolute("~/Configuration");
foreach (string path in Directory.EnumerateFiles(configPath, "*.xml"))
{
  // ...
}

However, the path resolves to C:\Configuration as evidenced by the error message:

Could not find a part of the path 'C:\Configuration\'.

What am I missing?

Upvotes: 0

Views: 387

Answers (1)

Marc
Marc

Reputation: 6771

I don't know but this should work in your controller:

string configPath = Server.MapPath("~/Configuration");

Upvotes: 1

Related Questions