删除文件夹后提示无法从服务器中检索文件夹信息。
删除代码:
 public bool DelDirectoryInfo(string path)
    {
        try
        {
            System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(path);
            if (di.Exists)
            {
                //try
                //{
                    di.Delete();
                    return true;
                //}
                //catch (Exception)
                //{
                //    return false;
                //} 
            }
            else
            {
               
                return false;
            }
        }
        catch (Exception error)
        {
            return false;
        }
    }

解决方案 »

  1.   

    删除文件夹下以:user 开头的所有文件
    foreach(string strFile in System.IO.Directory.GetFiles(this.Server.MapPath(@"C:\"),"user*"))
    {
    System.IO.File.Delete(strFile);
    }private void Button1_Click(object sender, System.EventArgs e)
    {//新建文件
       string path=Server.MapPath("index4.aspx");   
       //Response.Write(DateTime.Now.ToString("yyyymmdd"));
       
       //获得文件名
       int fileLen=path.LastIndexOf(".");
       int pathLen=path.Length;
       string tempName=path.Substring(fileLen,pathLen-fileLen);
       //获取文件路径
       int len=path.LastIndexOf(@"\");
       string tempPath=path.Substring(0,len)+"\\"+DateTime.Now.ToString("yyyymmddhhssmm")+tempName;
       try
       {
        File.Create(tempPath);
        Response.Write("<script>alert('新建文件成功');</script>");
       }
       catch(Exception ex)
       {
        Response.Write(ex.ToString());
       }
    }private void Button2_Click(object sender, System.EventArgs e)
    {//复制文件
       string path=Server.MapPath("index4.aspx");   
       //Response.Write(DateTime.Now.ToString("yyyymmdd"));
       
       //获得文件名
       int fileLen=path.LastIndexOf(".");
       int pathLen=path.Length;
       string tempName=path.Substring(fileLen,pathLen-fileLen);
       //获取文件路径
       int len=path.LastIndexOf(@"\");
       string tempPath=path.Substring(0,len)+"\\"+DateTime.Now.ToString("yyyymmddhhssmm")+tempName;
       try
       {
        File.Copy(path,tempPath);    
        Response.Write("<script>alert('复制文件成功');</script>");
       }
       catch(Exception ex)
       {
        Response.Write(ex.ToString());
       }
    }private void Button3_Click(object sender, System.EventArgs e)
    {//删除文件
       string path=Server.MapPath("index4.aspx");   
       //Response.Write(DateTime.Now.ToString("yyyymmdd"));
       
       //获得文件名
       int fileLen=path.LastIndexOf(".");
       int pathLen=path.Length;
       string tempName=path.Substring(fileLen,pathLen-fileLen);
       //获取文件路径
       int len=path.LastIndexOf(@"\");
       //string tempPath=path.Substring(0,len)+"\\"+DateTime.Now.ToString("yyyymmddhhssmm")+tempName;
       string tempPath=path.Substring(0,len)+"\\"+"20063702021337.aspx";
       
       try
       {
        File.Delete(tempPath);    
        Response.Write("<script>alert('删除文件成功');</script>");
       }
       catch(Exception ex)
       {
        Response.Write(ex.ToString());
       }
    }
      

  2.   

    asp.net C#删文件夹,记忆中好像是要删除文件夹里面所有的东西,才可以删的
      

  3.   

    给该目录赋上 asp.net用户或者internet来宾用户或者everyone用户的操作权限
      

  4.   

    应该不是权限和文件或者子文件夹的问题,楼主不是已经说了是删除文件夹后才出现的错误吗?我觉得可能是使用DirectoryInfo这个实例类引起的问题,改为使用静态成员的方法试试:System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(path); 
                if (di.Exists) 
                { 
                    //try 
                    //{ 
                        di.Delete(); 
                        return true; 
                    //} 改为:if (Directory.Exists(path)) 
                { 
                    //try 
                    //{ 
                        Directory.Delete(path); 
                        return true; 
                    //}