从项目文件夹中删除上传的文件 [英] Delete an uploaded file from project folder

查看:52
本文介绍了从项目文件夹中删除上传的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在asp.net中将一些文件上传到我的项目文件夹中,并且文件路径保存在我的数据库中.但是当我当时想从数据库中删除该记录时,必须从项目中删除相关文件文件夹.但是不能删除.请建议我...

I have uploaded some files to my project folder in asp.net and the file path is saved in my database..But when i want to delete that record from the database at that time the related file must be deleted from the project folder..But it is not deleting..Please suggest me...

推荐答案

protected void btnSubmit_Click(object sender, EventArgs e)
{
try {
FileInfo TheFile = new FileInfo(MapPath(".") + "\\" + txtFile.Text);
if (TheFile.Exists) {
File.Delete(MapPath(".") + "\\" + txtFile.Text);
}
else {
throw new FileNotFoundException();
}
}

catch (FileNotFoundException ex) {
lblStatus.Text += ex.Message;
}
catch (Exception ex) {
lblStatus.Text += ex.Message;
}

}




文件位于images文件夹中.

如果您的数据库路径是这样的话

图片\ demo.jpg




files are in images folder.

if Your DB path is like this means

Images\demo.jpg


string dbpath=getdbValue() // get it from DB

string delfile= System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath +dbpath

System.IO.File.Delete(delfile); 








问候,
朋友








regards,
Pal


这篇关于从项目文件夹中删除上传的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆