If you add a using System.IO or a reference to it, this should find all the .xml files in the App_Data folder, in your application environment:
DirectoryInfo di = new DirectoryInfo(Server.MapPath("/App_Data"));
var fi = di.EnumerateFiles("*.xml", SearchOption.TopDirectoryOnly);
// fi should contain the enumeration of files found at that path
// you can iterate over fi and have all the file info of each file found
[UPDATE]
If you already have the path string resolved, you can replace the entire Server.MapPath("/App_Data") with your path for a desktop app, and the rest stays the same.
To iterate over the collection just use a foreach loop as in:
foreach (FileInfo file in fi)
{
string s = "File Name: " + file.Name + "\r";
s += "Full Path: " + file.FullName + "\r";
s += "File Ext.: " + file.Extension + "\r";
MessageBox.Show(s);
}
[ UPDATE 2 ]
Since the OP is referring to a web scenario
By adding the using System.Web.Hosting statement to my controller I was able to test the 'HostingEnvironment.MapPath', in an mvc sample app.
Here's what I came up with.
This example locates the virtual path '/App_Data', gathers the '.xml' files it finds in the path.
Then it iterates over the collection and reads each file's contents into an array element.
Finally, it displays the file names as links in the view, as well as each file's content with a heading#.
Keep in mind that this may not be the most optimized code sample.
C# Code: in mvc Controller
DirectoryInfo di = new DirectoryInfo(HostingEnvironment.MapPath("/App_Data"));
var fi = di.EnumerateFiles("*.xml", SearchOption.TopDirectoryOnly);
ViewBag.Files = fi;
string[] fs = new string[fi.Count()];
int fc = fi.Count();
int x = 0;
foreach (FileInfo f in fi)
{
StreamReader sr = new StreamReader(f.FullName);
fs[x] = sr.ReadToEnd();
sr.Close();
if (x < fc) x++;
}
ViewBag.Contents = fs;
ViewBag.ContCount = fc;
Html: in View
<div>
<h3>Files Found:</h3>
<p>
@foreach (FileInfo f in @ViewBag.Files)
{
<a href="@f.FullName">@f.Name</a><br />
}
</p>
</div>
<div>
<h3>File Contents:</h3>
@for (int c = 0; c < @ViewBag.ContCount; c++)
{
<h4>Heading @(c)</h4>
<p>
@ViewBag.Contents[@c]
</p>
<hr />
}
</div>