日期:2014-05-20  浏览次数:20375 次

未将对象实例化问题
using   System;
using   System.Web;
using   System.Web.UI;
using   System.Web.UI.WebControls;
using   System.Web.UI.HtmlControls;
using   System.IO;
using   System.Collections;
public   class   onlineMag:Page
{
      public   Button   downopen,postup,createbtn,del;
      public   TextBox   createdir;
      public   HtmlInputFile   postfile;
      public   ListBox   showfile;
      public   static   string   CurrentPath;
      public   void   Page_Load(object   sender,EventArgs   e)
      {  
          if(!IsPostBack)
  {
      CurrentPath=Server.MapPath( "../CS ");
      if(!Directory.Exists(Server.MapPath( "../CS ")))
      {
            Directory.CreateDirectory(Server.MapPath( "../CS "));
      }
      LoadDir(CurrentPath);
  }
      }
      public   void   LoadDir(string   fullpath)
      {
          CurrentPath=fullpath;
  ArrayList   values=new   ArrayList();
  string[]   myfile,mydir;
  if(CurrentPath!=Server.MapPath( "../WebSite "))
  {
        values.Add( "返回上级目录 ");
  }
  myfile=Directory.GetFiles(fullpath);
  values.AddRange(myfile);
  mydir=Directory.GetDirectories(fullpath);
  values.AddRange(mydir);
  showfile.DataSource=values;
  showfile.DataBind();
      }
      public   void   del_Click(object   sender,EventArgs   e)
      {
                CurrentPath=Server.MapPath( "../CS ");
                LoadDir(CurrentPath);
File.Delete(Server.MapPath(Path.GetFileName(showfile.SelectedItem.Text)));
      }
}


运行File.Delete(Server.MapPath(Path.GetFileName(showfile.SelectedItem.Text)));
就出现未将对象实例化

------解决方案--------------------
看看aspx页里面有没有showfile这个ListBox控件
------解决方案--------------------
ding
------解决方案--------------------
Path.GetFileName
这个有问题。没有实例化过