ExtensionMethod.NET Home of 818 C#, Visual Basic, F# and Javascript extension methods

GetFilesInVirtualDirectory

This extension method acts similarly to Directory.GetFiles except that the directory path is expressed as a virtual directory.

Source

public static IEnumerable<string> GetFilesInVirtualDirectory(this Page targetPage, string directoryPath)
{
    return Directory.GetFiles(targetPage.Server.MapPath(directoryPath)).Select(f => Path.GetFileName(f));
}

Example

foreach (var file in GetFilesInVirtualDirectory("../Images")
{
  // Do something interesting.
}

Author: Casey

Submitted on: 19 apr 2011

Language: C#

Type: System.Web.UI

Views: 2409