Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save csharpforevermore/7156614 to your computer and use it in GitHub Desktop.
Save csharpforevermore/7156614 to your computer and use it in GitHub Desktop.
ASP.NET - get relative path to files in a specific folder
private IEnumerable<string> GetRelativePathsToRoot(string virtualPath, string filter)
{
var physicalPath = Server.MapPath(virtualPath);
var absolutePaths = Directory.EnumerateFiles(
physicalPath,
filter,
SearchOption.AllDirectories
);
return absolutePaths.Select(
x => Url.Content(virtualPath + x.Replace(physicalPath, ""))
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment