如何用File.Delete 方法批量删除文件
循环删除
//删除原附件文件
FS = SF.getStudentFileById(Convert.ToInt32(Request.QueryString["Student_Id"].ToString()));
string PicUrl1 = Server.MapPath("../studentfile/") + FS.StudentFile_FileMewName;
File.Delete(PicUrl1);上面这个是我要删除那里的代码
不对的 没有循环 只是取得了被删学生的Student_Id 学生不确定有多少附件File
循环删除
//删除原附件文件
FS = SF.getStudentFileById(Convert.ToInt32(Request.QueryString["Student_Id"].ToString()));
string PicUrl1 = Server.MapPath("../studentfile/") + FS.StudentFile_FileMewName;
File.Delete(PicUrl1);上面这个是我要删除那里的代码
不对的 没有循环 只是取得了被删学生的Student_Id 学生不确定有多少附件File
解决方案 »
- 紧急求助!关于网页调用DLL问题
- CheckBox绑定到gridview中做标记
- 关于pagination JQUERY分页插件的使用,在网上看了一些不过难懂
- 伪静态 页面里所有的链接都要改?
- 如何在页面加载时加入Loading提示
- 关于设定GridView中格式字符串和链接问题?
- DataGrid绑定RadioButtonList
- 提问关于自动生成TextBox后,怎样找到具体某个TextBox,并且到的里面具体的值啊?!!
- 求助:把COM对象放入到session中出现的问题
- 怎样使excel文件不在浏览器中打开而是直接提示用户存盘?
- 请教个VS05调试过程中主目录的问题
- 非常奇怪的问题,大家都来看看
取出的 .StudentFile_FileMewName 应该是个Listselect StudentFile_FileMewName from StudentFile where student_Id=....
public StuFileModels getStudentFileById(int StudentFile_Id)
{
string sql = "select StudentFile_Id,StudentFile_Name,StudentFile_FileName,StudentFile_FileMewName from StudentFile where StudentFile_Id=@StudentFile_Id order by StudentFile_Id desc";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("StudentFile_Id", SqlDbType.Int);
param[0].Value = StudentFile_Id;
DataTable temp = SqlHelper.ExecuteDataTable(CommandType.Text, sql, param); StuFileModels Ltemp1 = new StuFileModels();
if (temp.Rows.Count > 0)
{
Ltemp1.StudentFile_Id = Convert.ToInt32(temp.Rows[0]["StudentFile_Id"]);
Ltemp1.StudentFile_Name = temp.Rows[0]["StudentFile_Name"].ToString();
Ltemp1.StudentFile_FileName = temp.Rows[0]["StudentFile_FileName"].ToString();
Ltemp1.StudentFile_FileMewName = temp.Rows[0]["StudentFile_FileMewName"].ToString();
return Ltemp1;
}
else
{
return null;
}
}
//你的Student_ID是多项,你这里只取了第一项
if (temp.Rows.Count > 0)
{
Ltemp1.StudentFile_Id = Convert.ToInt32(temp.Rows[0]["StudentFile_Id"]);
Ltemp1.StudentFile_Name = temp.Rows[0]["StudentFile_Name"].ToString();
Ltemp1.StudentFile_FileName = temp.Rows[0]["StudentFile_FileName"].ToString();
Ltemp1.StudentFile_FileMewName = temp.Rows[0]["StudentFile_FileMewName"].ToString();
return Ltemp1;
}
//这里你直接返回Datatable,循环DataTable取得路径字段删除就可以
FS = SF.getStudentFileById(Convert.ToInt32(Request.QueryString["Student_Id"].ToString()));
string PicUrl1 = Server.MapPath("../studentfile/") + FS.StudentFile_FileMewName;
File.Delete(PicUrl1);
http://www.cnblogs.com/insus/articles/1986156.html
http://www.cnblogs.com/insus/articles/1986723.html
定时删除:
http://www.cnblogs.com/insus/articles/1431986.html
for (i=0;i<temp.Rows.Count ;i++)
{
Ltemp1[i].StudentFile_Id = Convert.ToInt32(temp.Rows[i]["StudentFile_Id"]);
Ltemp1[i].StudentFile_Name = temp.Rows[i]["StudentFile_Name"].ToString();
Ltemp1[i].StudentFile_FileName = temp.Rows[i]["StudentFile_FileName"].ToString();
Ltemp1[i].StudentFile_FileMewName = temp.Rows[i]["StudentFile_FileMewName"].ToString();
}
return Ltemp1;
DataTable dt = SF.getfile(Convert.ToInt32(Request.QueryString["Student_Id"].ToString()));
for (int i = 0; i < dt.Rows.Count; i++)
{
string PicUrl1 = Server.MapPath("../studentfile/") + dt.Rows[i]["StudentFile_FileMewName"].ToString();
File.Delete(PicUrl1);
int m = SF.StudentFileDelete1(Convert.ToInt32(Request.QueryString["Student_Id"].ToString()));
}
想问下File.Delete()中的参数可以是集合么?