如何下载和删除已上传到服务器上的文件。 下载直接作个链接到要下载的文件,删除用system.io中相应的类就可以轻松实现 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 删除时遇到下面的错误:未将对象引用设置到对象的实例。 说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 行 195: {行 196:行 197: string fileFullName=this.postedFile.FileName;行 198: string fileName=PathToName(fileFullName);行 199: aimPath+=fileName; 我猜原因是在datagrid对象中无法取得HtmlInputFile对象的实例。因为我发现HtmlInputFile对象的实例根本无法传递到datagrid对象或表格对象中。请问大家如何解决? 没明白你在什么地方出错了你是不是把HtmlInputFile作为datagrid对象的子控件,你可以通过findcontrol加upcast来得到,你所说的NullReferenceException发生在什么地方。一般说来,NullReferenceException比较容易处理,你debug跟踪一下,看相应的变量在运行时是不是空就知道了 form的enctype属性必须设成="multipart/form-data"否则<INPUT type="file">无效 程序如下: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); }请问大家哪儿错了啊? 你要是在服务器端删除的话,aimPath必须是服务器端的物理路径才可以删除,如果是ntfs分区,你必须增加ASPNET有修改这个文件夹的权限,你用的postedFile.FileName是客户端上传的本机路径吧? 你取aim的服务器端的路径就可以啦,你把文件存那里啦??要是存数据库里的话你就update tablename set file='' where &^%*@#$^@#$ 下载直接通过http地址下载。删除的话可以通过webDav协议删除. using System.IO;File.Delete(Server.MapPath("yourfilename")); 关于treeview C#打包程序安装360报告说没签名 VS2008的问题 VS2008开发的.NET2.0项目,如何去除对.NET3.5的依赖 winform间传递数值的问题 大虾们 谁能帮助用olb方法增加记录,现在的语句为如下,下面怎么写 求教各位:桌面程序datagrid 随着窗体改变大小 winform下怎么模拟数字键盘输入 《C# Web编程》和《C# Windows编程》这两本书怎么样啊?有没有人看过的? 大神们帮忙下初学者 如何在web页面中实现像windows窗口式的对文件直接操作,往服务器上上传、下载、删除? Assembly 这个究竟有什么用
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 195: {
行 196:
行 197: string fileFullName=this.postedFile.FileName;
行 198: string fileName=PathToName(fileFullName);
行 199: aimPath+=fileName;
我猜原因是在datagrid对象中无法取得HtmlInputFile对象的实例。因为我发现HtmlInputFile
对象的实例根本无法传递到datagrid对象或表格对象中。请问大家如何解决?
你是不是把HtmlInputFile作为datagrid对象的子控件,你可以通过findcontrol加upcast来得到,你所说的NullReferenceException发生在什么地方。
一般说来,NullReferenceException比较容易处理,你debug跟踪一下,看相应的变量在运行时是不是空就知道了
否则<INPUT type="file">无效
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);
}请问大家哪儿错了啊?