I currently learning about ASP.NET MVC 4.
I want to display .cs
and .cpp
files located in a directory on the web page. But somehow I get exception for multiple file type display.
Below line of code gives exception:
string pattern ="*.cs|*.cpp";
Till now I wrote below code:
public ActionResult Contact()
{
string pattern = "*.cs";
//string pattern ="*.cs|*.cpp"; // this line does not work
ViewBag.Message = "Your contact page.";
DirectoryInfo dirInfo = new DirectoryInfo(@"f:\");
List<string> filenames = dirInfo.GetFiles(pattern).Select(i => i.Name).ToList();
ViewBag.data = filenames;
return View(filenames);
}
The View code looks like:
@{
ViewBag.Title = "Contact";
}
<hgroup class="title">
<h1>@ViewBag.Title.</h1>
<h2>@ViewBag.Message</h2>
</hgroup>
<table bgcolor="#00FF00">
@foreach (var item in (List<string>)ViewBag.data)
{
<tr>
<th>@item <br></th>
</tr>
}
</table>