?
Solved

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

Posted on 2006-06-23
3
Medium Priority
?
815 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 1000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

762 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