Solved

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

Posted on 2006-06-23
3
806 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 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