下载直接作个链接到要下载的文件,删除用system.io中相应的类就可以轻松实现

解决方案 »

  1.   

    删除时遇到下面的错误:未将对象引用设置到对象的实例。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
    行 195: {
    行 196:
    行 197: string fileFullName=this.postedFile.FileName;
    行 198: string fileName=PathToName(fileFullName);
    行 199: aimPath+=fileName;
     
    我猜原因是在datagrid对象中无法取得HtmlInputFile对象的实例。因为我发现HtmlInputFile
    对象的实例根本无法传递到datagrid对象或表格对象中。请问大家如何解决?
      

  2.   

    没明白你在什么地方出错了
    你是不是把HtmlInputFile作为datagrid对象的子控件,你可以通过findcontrol加upcast来得到,你所说的NullReferenceException发生在什么地方。
    一般说来,NullReferenceException比较容易处理,你debug跟踪一下,看相应的变量在运行时是不是空就知道了
      

  3.   

    form的enctype属性必须设成="multipart/form-data"
    否则<INPUT type="file">无效
      

  4.   

    程序如下:
    int count=this.DataGrid1.Items.Count;
    if(count!=0)
    {
    HtmlInputCheckBox cb=new HtmlInputCheckBox ();
    for(int i=0;i<count;i++)
    {
    cb=(HtmlInputCheckBox)this.DataGrid1 .Items [i].FindControl ("check");
    if(cb.Checked ==true)
    {
    int id =int.Parse (DataGrid1 .Items [i].Cells[3].Text);
    jpda.CommandText="delete from uploadfile where id="+id.ToString ();
    string error = null;
    jpda.ExcuteNonQuery(out error);
    uf.Delete();
    }
    }
    }
    public void Delete()
    { string fileFullName=this.postedFile.FileName;
    int pos=fileFullName.LastIndexOf("\\");
    string fileName=fileFullName.Substring(pos+1);
    aimPath+=fileName;
    System.IO.File.Delete(aimPath);
    }请问大家哪儿错了啊?
      

  5.   

    你要是在服务器端删除的话,aimPath必须是服务器端的物理路径才可以删除,如果是ntfs分区,你必须增加ASPNET有修改这个文件夹的权限,你用的postedFile.FileName是客户端上传的本机路径吧?
      

  6.   

    你取aim的服务器端的路径就可以啦,你把文件存那里啦??要是存数据库里的话你就update tablename set file='' where &^%*@#$^@#$
      

  7.   

    下载直接通过http地址下载。删除的话可以通过webDav协议删除.
      

  8.   

    using System.IO;File.Delete(Server.MapPath("yourfilename"));