How to check if a media item is deleted? Options
EmKay
Posted: Monday, October 27, 2008 3:07:36 PM
Rank: Newbie

Joined: 2/28/2008
Posts: 9
Hi

I have a usercontrol on which I check the media of a media picker property.
However, when a media item is selected with the media picker and the media is then deleted in the media archive, an error occures.

The error is as follows:

Quote:
Object reference not set to an instance of an object.


And the line causing the error is this:
Code:

strLink = objFile.Current.SelectSingleNode("/node/data [@alias='umbracoFile']").InnerXml

Before that, objFile is declared like this:

Code:
Dim objFile As System.Xml.XPath.XPathNodeIterator = umbraco.library.GetMedia(intMediaId, False)

intMediaId is the id of the media item selected in the media picker.

It's working fine when the media is still in the media archive, but if you delete it before removing the reference the error above is raised.

How do I check if the media item still exists in the media archive?

objFile Is Nothing does not work.
Scott the God
Posted: Tuesday, October 28, 2008 11:20:19 AM

Rank: Devotee

Joined: 10/16/2008
Posts: 64
Location: Spain
so what about using a try catch block?

Code:

Try
Dim objFile As System.Xml.XPath.XPathNodeIterator = umbraco.library.GetMedia(intMediaId, False)
Catch
End Try


Scott

Scott
EmKay
Posted: Tuesday, October 28, 2008 11:24:23 AM
Rank: Newbie

Joined: 2/28/2008
Posts: 9
Doh.. Of course! :D

I will try that.. Thanks :P
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.