删除数据库中的图像路径,并从asp.net中的文件夹中删除图像 [英] delete Image path from database and also delete image from folder in asp.net

查看:84
本文介绍了删除数据库中的图像路径,并从asp.net中的文件夹中删除图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将图像路径存储在一个文件夹以及database.so我需要当用户从数据库中删除图像时,同一时间文件夹中的图像应该是delete.plz让我知道如何实现。

i store a image path in a folder as well as database.so i need when a user delete a image from database same time image within folder should be delete.plz give me idea how to implement .

推荐答案

编写一个存储过程,在第一次存储图像名称的变量中然后从数据库中删除记录,然后将该变量值返回给调用方法,这里检查值是否有效,如果有效则返回值为图像的路径,如果没有则则删除记录时发生错误。现在你可以从文件夹中删除图像文件了。

如下所示...



Write a stored procedure, in that first store the image name in a variable and then delete the record from the database, and then return that variable value to the calling method, here check the value is valid or not, if valid then the return value is Path of the image, if not then surly the error has occured while deleting record. now you can delete the image file from the folder.
as like below...

System.IO.File.Delete(path);


您好,

您可以使用SqlTransaction在此事务下从数据库中删除图像。然后从文件夹中删除图像。

我认为您可以使用此代码删除图像:



Hi,
You can use SqlTransaction to delete the image from database under this transaction. Then delete the image from the folder.
I think you can use this code to delete image :

string filePath = Server.MapPath("~/" + PathDB);
if (System.IO.File.Exists(filePath))


{


System.IO.File.Delete(filePath);


}



其中PathDB包含数据库的路径。

我希望它对你有所帮助。

祝你好运


Where PathDB contains the path from database.
I hope it will be helpful for you.
good luck


你好Mavendra,



试试这个链接 [< a href =http://stackoverflow.com/questions/17214008/delete-a-file-from-database-and-file-systemtarget =_ blanktitle =New Window> ^ ] 。

希望它对你非常有用。



问候,

RK
Hi Mavendra,

Try this link[^].
Hope it will be very useful to you.

Regards,
RK


这篇关于删除数据库中的图像路径,并从asp.net中的文件夹中删除图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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