Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5 > BOOK: Beginning ASP.NET 4.5 : in C# and VB
|
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 9th, 2013, 01:30 AM
Registered User
 
Join Date: Mar 2013
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Deleting image files after deleting a picture

Hi,

One of the things that I noticed is that images are not deleted after deleting a picture from an album. I'm only on Chapter 14, but I verified that this is in the final code by running it. I wanted to add code so that a picture would be deleted after successfully deleting a picture record from the Pictures table. I figured that this would be done in the code behind for ManagePhotoAlbum. So I created an EntityDataSource1_Deleting event. My plan was to cast e.Entity to a Picture, use the ImageUrl to get the name, and use File.Delete. But when I look at ((Picture)e.Entity).ImageUrl, the value is null. The only value available is the Id column. I was kind of hoping that there might be a way to use LINQ to get the ImageUrl for the Id that I have. But I couldn't figure out a way to do that.

Any suggestions?

Thanks.
 
Old March 9th, 2013, 09:30 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

After the post back, the Picture is reconstructed from ViewState, Since the ImageUrl was never stored there, it's not available in ViewState. You can work around this in two ways:

1. Query the object from the EF model again based on the Id of the Picture entity. This requires another trip to the database.

2. Store the ImageUrl in ViewState by adding it to the DataKeyNames property of the ListView.

Exercise 4 of Chapter 14 has an example of the latter.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting a Picture on The Server zaeem Classic ASP Professional 1 September 8th, 2005 01:31 AM
Deleting a Picture on The Server zaeem Classic ASP Databases 1 May 6th, 2005 11:32 AM
deleting files as session expires jaisonkmathews General .NET 4 October 18th, 2004 12:07 AM
Deleting directories and files ... DennisTh VB.NET 2002/2003 Basics 5 June 12th, 2003 02:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.