如何删除以上传的文件?急啊,高分求救!

liq1979 2003-08-08 09:37:19
如标题!
...全文
31 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wacle 2003-08-08
  • 打赏
  • 举报
回复
按照 river168(海阔天空.net)的方法,可以的.
HPsoft 2003-08-08
  • 打赏
  • 举报
回复
System.IO.File.Delete("c:\\temp\\file.bak")
  • 打赏
  • 举报
回复
Javascript的没有找到!
river168 2003-08-08
  • 打赏
  • 举报
回复
从数据库取出文件名,加上硬盘的绝对路径,再删除.

参考代码:

private void DeletePic(int id)
{
string sqlstr="select pic from product where id=" +id.ToString();
OleDbConnection conn=new OleDbConnection(Application.Get("connstr").ToString());
conn.Open();
OleDbCommand cmd=new OleDbCommand(sqlstr,conn);
cmd.CommandType=CommandType.Text;
string picPath=((object)cmd.ExecuteScalar()).ToString();
if (picPath.Length!=0)
{
int i= picPath.LastIndexOf(@"\");
//取得文件名
string fileName =picPath.Substring(i);

picPath=Application.Get("uploadpath").ToString()+fileName;
if(File.Exists(picPath))
{
File.Delete(picPath);
}
}
sqlstr="select smallpic from product where id="+id.ToString();
cmd.CommandText=sqlstr;
cmd.CommandType=CommandType.Text;
picPath=((object)cmd.ExecuteScalar()).ToString();
if (picPath.Length!=0)
{
int i= picPath.LastIndexOf(@"\");
//取得文件名
string fileName =picPath.Substring(i);

picPath=Application.Get("uploadpath").ToString()+fileName;
if(File.Exists(picPath))
{
File.Delete(picPath);
}
}
conn.Close();
}

  • 打赏
  • 举报
回复
Javascript:


public void DeleteImage_OnClick(object sender, EventArgs e) {
if (FileToDelete.Value != "" && FileToDelete.Value != "undefined") {
try {
string AppPath = HttpContext.Current.Request.PhysicalApplicationPath;
System.IO.File.Delete(AppPath + CurrentImagesFolder.Value + "\\" + FileToDelete.Value);
ResultsMessage.Text = "Deleted: " + FileToDelete.Value;
} catch(Exception ex) {
ResultsMessage.Text = "There was an error.";
}
} else {
ResultsMessage.Text = NoFileToDeleteMessage;
}
DisplayImages();
}

62,071

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧