Problems listing Favorites and Subscriptions

Vote:
 
Hello. I´m ading favorites to the PersonalizedData object with this code: if(PersonalizedData.Current["Favorites", CurrentPage.PageLink] == null) PersonalizedData.Current["Favorites", CurrentPage.PageLink] = "true"; And when i´m listing the Fovirets on an other template I use this code: if (PersonalizedData.Current != null) { plcBookmarks.Controls.Add(new LiteralControl("\n")); PageBase oPage = (PageBase)this.Page; PageData oPersonalizedPage; for (int j=0; j<=opage.currentuser.userdata.personalizedpages.length-1 ; j++) { opersonalizedpage="oPage.GetPage(oPage.CurrentUser.UserData.PersonalizedPages[j]);" opage.currentuser.userdata.personalizedpages. lnkbtn="new" linkbutton(); lnkbtn.id="oPersonalizedPage.PageLink.ToString();" lnkbtn.click +="new" system.eventhandler( removebookmark ) ; lnkbtn.text="CurrentPage.Property["Remove"].ToString();" plcbookmarks.controls.add(new literalcontrol(">\n\n")); plcBookmarks.Controls.Add(new LiteralControl("\n\n")); } plcBookmarks.Controls.Add(new LiteralControl("
" + oPersonalizedPage.PageName.ToString() + "")); plcBookmarks.Controls.Add(lnkBtn); plcBookmarks.Controls.Add(new LiteralControl("
\n")); }
The problem is that this listing allso shows the pages I´m subscribed to. I understand this, so I did this another way: if(PersonalizedData.Current["Favorites"] != null) { plcBookmarks.Controls.Add(new LiteralControl("\n")); ArrayList alFavorites = StringToArrayList(PersonalizedData.Current["Favorites"].ToString()); for(int iCnt=0; iCnt<=alfavorites.count-1; icnt++) { string[] tmpbm="(string[])alFavorites[iCnt];" pagedata pd="GetPage((PageReference)" alfavorites[icnt]); lnkbtn="new" linkbutton(); lnkbtn.id="pd.PageLink.ToString();" lnkbtn.click +="new" system.eventhandler( removebookmark ) ; lnkbtn.text="CurrentPage.Property["Remove"].ToString();" plcbookmarks.controls.add(new literalcontrol(">\n\n")); plcBookmarks.Controls.Add(new LiteralControl("\n\n")); } plcBookmarks.Controls.Add(new LiteralControl("
" + pd.PageName + "")); plcBookmarks.Controls.Add(lnkBtn); plcBookmarks.Controls.Add(new LiteralControl("
\n")); }
But this does not work at all. it stops at the first IF-statment. Does someone have a solution for this problem? /Emil
#12942
Feb 16, 2007 13:57
Vote:
 
I'm not going to tell you to not build your html as a string through code like you're doing here (oops, I just did :-) ) What you're trying to do, as I can understand from you code, is to list all the pages that has been stamped as a favourite. You're storing the favourite flag on the page with this code: PersonalizedData.Current["Favorites", CurrentPage.PageLink] = "true"; And the list you're building should only show personalized items of the type "Favorites", but also shows additional personalized data like the EPSUBSCRIBE key that is also part of this data. The CurrentUser.UserData.PersonalizedPages gives you an array of all pages that has personalized data attached to them. It does not filter on the type of data (the key used to store it), it will simply return all of it. What you need to do after you've got that PageReference array is to check if that page has a "Favorites" item. if (CurrentUser.UserData["Favorites", pageRef] != null) ... where the pageRef is each of the PageReferences in the array returned from PersonalizedPages. So the code should look something like this: if (PersonalizedData.Current == null) return; PersonalizedData userData = PersonalizedData.Current; foreach (PageReference pageRef in userData.PersonalizedPages) { if (userData["Favorites", pageRef] != null) { bool isFav = bool.Parse(userData["Favorites", pageRef].ToString()); if (isFav) // Do your thing } } Haven't tested the code (I'm just jotting it down from memory and the SDK.) It shouldn't be too far off. /Steve
#15127
Feb 16, 2007 16:08
Vote:
 
Thanks for the help! The if-statement fixed it. /e
#15128
Feb 20, 2007 8:30
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.