views:

327

answers:

1

I have been breaking my head over this. I appreciate any help.

I have a custom PersonalizationProvider, custom WebPartManager and custom WePart class. I have custom data tables for storing the Personalization Data per user. My task is to programmtically loop through all the web parts added by each user so that I can set a personalizable attribute.

According to the documentation, FindState method returns a PersonalizationStateInfoCollection for a given PersonalizationStateQuery:

PersonalizationStateQuery pq = new PersonalizationStateQuery();
pq.PathToMatch = path;
pq.UsernameToMatch = userName;
int count;
CustomPersonalizationProvider provider= new CustomPersonalizationProvider();
PersonalizationStateInfoCollection pcol = provider.FindState(PersonalizationScope.User, pq, 0, Int32.MaxValue, out count);

PersonalizationProvider is an abstract class and I will have to provide my own implementation for the FindState method in my custom class. I have spent last 6 hours trying to find something and I don't know how to implement this method.

The PersonalizationData is blob. I could deserialize it to object array. But nothing further. I have no idea how to serialize/deserialize that blob in to PersonalizationStateInfoCollection.

String BlobString = Convert.ToBase64String(UserDataBlob);
ObjectStateFormatter formatter = new ObjectStateFormatter();
Object[] DeserializedObjects = (Object[])formatter.Deserialize(BlobString);

Does anyone know how WebPartManager serializes the UserPersonalizationData in to the byte array that is stored in the database?

A: 

Try inherit your provider from SQLPersonalizationProvider instead of PersonalizationProvier. This way you don´t have to implement the FindState, ResetState, ReserUserState and GetCountOfState methods.

Several months ago I was trying to decode those bytes, but I gave up when I discovered that I didn´t really have to write it using this trick.

But I'm thinking that's not a perfect solution. If your provider use Oracle, MySql or anything but SQL Server, you'll find that after calling the Initialize method of your personalization provider, it will start to ask for the aspnet standard stored procedures in the database.

alcastro