Link to home
Start Free TrialLog in
Avatar of DCRJDS
DCRJDS

asked on

Delete Image File with <asp:CommandField ShowDeleteButton-"True" />

I have a <asp:CommandField  ItemStyle-ForeColor="Red" ShowDeleteButton="True"  /> that runs a stored procedure against SQL 2005 and deletes a record containing the photos filepath in a table.  I would also like to DELETE the actual photp.jpg from the Images Folder on the Web Server.  How would I accomplish this?
Avatar of gregg1ep00
gregg1ep00

System.IO.File.Delete( Server.MapPath( ResolveUrl( "~/images/photp.jpg" ) ) );

ResolveUrl method gives you the full path (in web url format) to your image (/webapp/images/photp.jpg)

Server.MapPath method changes that path to the physical location (C:\inetpub\wwwroot\...)
Avatar of DCRJDS

ASKER

on the editphoto.aspx page there is an <asp:GridView> that displays a table of photos that can be deleted from the Photo Table.(just the record).   When the user hits delete next to on of  the Photo sit runs the  (DeleteCommand="delete_photo" DeleteCommandType="StoredProcedure"  ) and it is taken out of the Photo table.  How do I use System.IO.File.Delete( Server.MapPath( ResolveUrl( "~/images/photp.jpg" ) ) );
from this same DELETECommand?
ASKER CERTIFIED SOLUTION
Avatar of gregg1ep00
gregg1ep00

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial