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


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


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


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

Author: Casey

Submitted on: 19 apr 2011

Language: C#

Type: System.Web.UI

Views: 4202