Solved

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

Posted on 2006-06-23
3
801 Views
Last Modified: 2010-08-05
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?
0
Comment
Question by:DCRJDS
  • 2
3 Comments
 
LVL 4

Expert Comment

by:gregg1ep00
ID: 16969469
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\...)
0
 

Author Comment

by:DCRJDS
ID: 16971964
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?
0
 
LVL 4

Accepted Solution

by:
gregg1ep00 earned 250 total points
ID: 16972442
Sorry.  You'll have to handle the RowDeleting event and do it there:


      protected void gvw_RowDeleting( object sender, GridViewDeleteEventArgs e )
      {
            System.IO.File.Delete( Server.MapPath( ResolveUrl( (string) e.Values["PhotoFilename"] ) ) );
      }

Replace "PhotoFilename" with the name of the field in your database that identifies the location of the file.

Greg
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question