|
Home > Archive > Microsoft Content Management Server > August 2005 > check posting is valid or not
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
check posting is valid or not
|
|
| andrew007 2005-08-26, 8:50 pm |
| I want to know why I am getting exception error when I try the following..
Posting posting = (Posting) context.Searches.GetByGuid(sGuid);
I get the following error.
"Specified cast is not valid."
Do you think it's b/c of posting expired or ?
is there any way I can test posting's validity w/Guid?
| |
| Stefan [MSFT] 2005-08-27, 2:49 am |
| Hi Andrew,
sounds as if the GUID identifies an object that is not a Posting.
E.g. a Channel, Resource, Resource Gallery, Template, Template Gallery.
In addition you should use the "AS" cast rather then the explicit cast as
this avoids exceptions:
Posting posting = context.Searches.GetByGuid(sGuid) as Posting;
To handle different types you could use this:
HierarchyItem hi = context.Searches.GetByGuid(sGuid);
if (hi is Posting)
{
Posting posting = hi as 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
----------------------
"andrew007" <gahdhi@yahoo.com> wrote in message
news:33DC314A-0987-435C-875F-4B73AF30AEA9@microsoft.com...
>I want to know why I am getting exception error when I try the following..
>
> Posting posting = (Posting) context.Searches.GetByGuid(sGuid);
>
> I get the following error.
> "Specified cast is not valid."
>
> Do you think it's b/c of posting expired or ?
> is there any way I can test posting's validity w/Guid?
>
>
>
>
| |
| andrew007 2005-08-29, 5:57 pm |
| Thanks it works great!!
"Stefan [MSFT]" wrote:
> Hi Andrew,
>
> sounds as if the GUID identifies an object that is not a Posting.
> E.g. a Channel, Resource, Resource Gallery, Template, Template Gallery.
>
> In addition you should use the "AS" cast rather then the explicit cast as
> this avoids exceptions:
>
> Posting posting = context.Searches.GetByGuid(sGuid) as Posting;
>
> To handle different types you could use this:
>
> HierarchyItem hi = context.Searches.GetByGuid(sGuid);
> if (hi is Posting)
> {
> Posting posting = hi as 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
> ----------------------
>
>
> "andrew007" <gahdhi@yahoo.com> wrote in message
> news:33DC314A-0987-435C-875F-4B73AF30AEA9@microsoft.com...
>
>
>
|
|
|
|
|