问题描述
usingSystem;usingSystem.Collections;usingSystem.Configuration;usingSystem.Data;usingSystem.Linq;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.HtmlControls;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Xml.Linq;usingSystem.IO;publicpartialclassfileManage_fileList:System.Web.UI.Page{BaseClassbc=newBaseClass();protectedvoidPage_Load(objectsender,EventArgse){GridView1.DataSource=bc.GetDataSet("select*from[file]","file");GridView1.DataKeyNames=newstring[]{"fileID"};GridView1.DataBind();}protectedvoidGridView1_RowDeleting(objectsender,GridViewDeleteEventArgse){//清除相片文件(服务器)DataSetds=bc.GetDataSet("select*from[file]wherefileID='"+this.GridView1.DataKeys[e.RowIndex].Value.ToString()+"'","file");DataRow[]row=ds.Tables[0].Select();foreach(DataRowrsinrow)//将检索到的数据逐一,循环添加到Listbox1中{FileInfofile=newFileInfo(Server.MapPath(rs["Path"].ToString()));file.Delete()在这里会提示异常System.IO.IOExeception怎么解决}//清除数据bc.ExecSQL("deletefrom[file]wherefileID='"+this.GridView1.DataKeys[e.RowIndex].Value.ToString()+"'");GridView1.DataSource=bc.GetDataSet("select*from[file]","[file]");GridView1.DataBind();}protectedvoidGridView1_PageIndexChanging(objectsender,GridViewPageEventArgse){GridView1.PageIndex=e.NewPageIndex;GridView1.DataBind();}}
解决方案
解决方案二:
看下要删除的文件是否存在?
解决方案三:
不让删除,有多种可能:1.配置错误,要删除的文件不存在。2.文件被其他进程打开3.文件没有操作权限,特别是win2008及以后系统,需要授权
解决方案四:
存在的,我都确认过了
解决方案五:
引用3楼dai1130的回复:
存在的,我都确认过了
文件被其他进程独占?