GetAppProfilePath("文件夹2");
private static string GetAppProfilePath(string foldType)
{
Assembly asm = Assembly.GetEntryAssembly() ;
string path = Path.GetDirectoryName(asm.Location) ; string[] dirs = null ;
while ( true ) 
{
dirs = Directory.GetDirectories(path, foldType) ;
if ( dirs.Length > 0 ) break ; DirectoryInfo dirInfo = Directory.GetParent(path) ;
if ( dirInfo == null ) break ;
path = dirInfo.FullName ;
}
return ( dirs != null ) ? dirs[0] : null ;
}

解决方案 »

  1.   

    不能用Server.MapPath直接去获取路径吗
      

  2.   

    1、string path = Server.MapPath("WebForm1.aspx").Replace("WebForm1.aspx","")+photoPath+"\\";//这里是变量
    if(!Directory.Exists(path)) //判断path路径是否存在
    {
    Directory.CreateDirectory(path); //如不存在则创建
    }2、string path = Server.MapPath(@"..\文件夹2\文件夹3")+direcotryName+"\\";//这里是变量
    if(!Directory.Exists(path)) //判断path路径是否存在
    {
    Directory.CreateDirectory(path); //如不存在则创建
    }
    以上代码未经调试,如有错误还请自行更正~~~
      

  3.   

    Server.MapPath能取到虚拟目录的路径吗?