| Stefan [MSFT] 2006-04-27, 7:27 am |
| Hi Tom,
first of all: you should use the "as" cast:
PostingItem = CmsHttpContext.Current.Searches.GetByPath(SubChannelItem.Path
+
SubChannelItem.DefaultPostingName) as Posting;
This will avoid exceptions.
The problem can occur if
a) the search returns "null" means no object with this name exists
b) a channel with the same name exists as your Default Posting. Then you
would get a Channel object which cannot be casted to Posting.
Cheers,
Stefan
--
This posting is provided "AS IS" with no warranties, and confers no rights
New to MCMS?
Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
Check out the new book as well: Advanced MCMS development:
http://tinyurl.com/8ugwj
----------------------
"Tom" <Tom@discussions.microsoft.com> wrote in message
news:F9FD2B7D-6887-45AA-8289-0EACA32EE613@microsoft.com...
> My CMS application compiles just fine with this line. Note: I had to
> cast
> the result as a Posting object.
>
> Posting PostingItem;
> PostingItem =
> (Posting)CmsHttpContext.Current.Searches.GetByPath(SubChannelItem.Path +
> SubChannelItem.DefaultPostingName);
>
>
> But when I run my application, I get the following error:
>
> Specified cast is not valid
>
> Can anyone assist?
>
> Note: I don't have a posting in the channel as of yet. My next line of
> code checks to see if its null but I'm not getting that far.
>
>
>
> if (PostingItem != null)
>
> Thanks
>
> Tom
>
>
|