Im having trouble when using the following code:
PageReference listingContainer = (PageReference)DataFactory.Instance.CurrentPage["RssSource"];
PageDataCollection children= DataFactory.Instance.GetChildren(listingContainer, LanguageSelector.AutoDetect(true));
the value of listingcontainer is null dispite ive set an internal pageUrl in the edit settings. so when im getting the children it says:
System.NullReferenceException: Object reference not set to an instance of an object. and points to listingcontainer. now im no einstein but basicly it says that the pageref=null. But the page got the property...
ive looked all over the place to see whats wrong or what the pageref is depended on but without luck finding any answers.
Someone who can point me in the right direction?
I think the problem with your code is DataFactory.Instance.CurrentPage. You should never get the current page form the data factory singelton. In fact, I was surprised the property even existed, but it seems like it needs to be there to fulfil the IPageSource interface.
If this code is a template I guess that you inherite from the PageBase class. If so, you should have access to a CurrentPage property directly on your class, which is what you should use.
Per GunsarfsEPiServer Development Team
Thnx for your reply!
I did use the CurrentPage property direclty at the beginning but i got the same problem. I decided to try to change it to datafactory instead but with the same result.
i accessed the page property earlier by :
PageReference listingContainer = (PageReference)CurrentPage["RssSource"]
same with getchildren
It does inherit from pageBase as it should. Perhaps i missinterpreted what you meant by accessing the currentpage property directly on my class?
After a discussion with a friend that mentioned it should state Datafactory instead i decided to try that instead. But i get the same error with both of them. This is strange because we use pageref on more pages than this one and it works like a charm.
You seem to have understood me perfectly, PageReference listingContainer = (PageReference)CurrentPage["RssSource"] is the correct way to write the code. So if listingContainer is null that means that there is no value set for "RssSource" on the page.
Think you need to access it like CurrentPage.Property["RssSource"]
What property type is your RssSource property? The property value can only be directly cast to PageReference if it is a property of type Page. If you are using Url to page/external address, the property value will be a string. You can however parse that string to a page reference.
PageReference link = PageReference.Parse(CurrentPage["RssSource"] as string);
That won't work for non-local pages of course, so check if you got a pagereference out by using PageReference.IsNullOrEmpty(link);
First of all thnx for the replies!
1. I know that there is a value it just seems like the value cant bee read or it really doesnt save the value to the property thus telling me its null.
2. The CurrentPage.property[index] is index based and i need to rewrite the function. No problem but it should work as it is now?
3. I think the right answer lies in what magnus Paulsson is describing about Url to page/external address property since its what im using. So i will test what is suggested and report back ASAP...
Thnx again for all input!
The CurrentPage.Property["Prop"] indexer returns the PropertyData object for the property value. CurrentPage["Prop"] returns the value of the property, that is to say CurrentPage["Prop"] will return the same as CurrentPage.Property["Prop"].Value (but watch out, Property["Prop"] could be null here).
Aha ok, thats correct. My mistake, was in a rush.
Tried the example above and it worked, however now i get :
Invalid PageReference format: /FirstFolder/SecondFolder/ThirdFolder/Page.aspx?id=24904 <--Its the internal link (not the real btw in order to not compromise security).
Im guessing i have to parse the string into a complete url or something or is it sufficient with the string above?
Ah, my mistake! You should use ParseUrl, not Parse.
Whoho nice. Works perfectly.
Thnx all for helping a Epi newbie out...