Wednesday, August 10, 2011

C# Get ALL Image File In a Folder

protected List GetFilesInFolder(string folderVirtualPath)
string physicalPathToFolder = Server.MapPath(folderVirtualPath);// Get the physical path
string filterExpression = "*.gif";
string[] physicalPathsCollection = System.IO.Directory.GetFiles(physicalPathToFolder,
filterExpression);// Get all child files of the given folder
List virtualPathsCollection = new List();// Contains the result
foreach (String path in physicalPathsCollection)
// The value of virtualPath will be similar to '~/PathToFolder/Image1.jpg
string virtualPath = VirtualPathUtility.AppendTrailingSlash(folderVirtualPath) +
return virtualPathsCollection;

No comments:

Post a Comment