C# webForm 文件访问 路径
时间:2011-04-14 来源:鱼不爱水
string[] getDirectoryFiles(string dirVPath, string pattern)
{
string dirVPathRooted = string.Concat(
HttpContext.Current.Request.ApplicationPath.ToLower(),
dirVPath);
string dirPath = HttpContext.Current.Server.MapPath(dirVPathRooted);
string[] files = Directory.GetFiles(dirPath, pattern, SearchOption.AllDirectories);
string[] includes = new string[files.Length];
for (int i = 0; i < files.Length; i++)
{
includes[i] = files[i]
.Replace(dirPath, dirVPath) // replace physical root by virtual root
.Replace('\\', '/');
}
return includes;
}