In a fragment of a code I’m working on, I must serialize a collection of links into an XML file. Fortunately, .NET Framework provides a quick XmlSerializer class to do the dirty job for you.
If you try to serialize a class derived from CollectionBase, the Serialize method will throw a nasty exception.
Use a container class, put the CollectionBase-derived class as a property, decorate this property with XmlArray and XmlArrayItem tags.
public class CollectionContainer
private LinkCollection _links= new ColeccionEnlaces();
public LinkCollection Links
_links = value;
If you are used to the ASP.NET Cache object, you can use it in SharePoint (after all, it’s just an ASP.NET extended application). However, the Web part framework encapsulates this Cache and enables you to have per-webpart and per-user cache. How? After a little bit of investigation I’ve found it out. The reason was to find out how to remove a cached item outside the webpart.
After inserting a key/value pair using SharePoint’s PartCacheWrite method, SharePoint creates an entry in the Application Cache object (remember that the cache is shared among all the users), with a custom prefix attached to your own key. This prefix includes:
- SharePoint webpart key:
- Request URL
- Creation date and time of the containing WebPartPage
- Webpart UniqueID
- User Security Identifier (SID) in hexadecimal format
- “?” character which marks the end of SharePoint prefix
- Your own key
So, let’s say you’ve cached an object within a webpart named “_ctl6” (default names for no-name webparts) with a key of “abc” and that the webpart is placed under the URL “/C7/Informatica/default.aspx”. The real cache key is:
It can be broken into the key components:
is composed of:
- 09/27/2006 11:49:49 (Creation date of the URL page in SharePoint server time)
(UniqueID of the webpart)
(User SID in hex format)
- ? (separating character)
(your custom key)
It also inserts two dependency strings, used to invalidate per-webpart or per-user cached data. The names of those keys are Depend_String and Depend_String_Per_User, followed by a SharePoint webpart key: