Help with WebPartCollection



Hi,
I have a problem checking if a webpart exist in the collection and add it if
it does not exist.
My problem is that a new webpart is added everytime the code runs.. Clearly
not what I want to happen.
Here is my code below:

//Code Snippet

SPWeb web = site.OpenWeb (url);
SPFile file = web.GetFile("default.aspx");
SPWebPartCollection parts = file.GetWebPartCollection (Storage.Shared);

WSSCFooter.WebPartFooter footer = new WSSCFooter.WebPartFooter();
footer.ZoneID = "BottomZone";
footer.Title = "Footer";


if (!parts.Contains(footer))
{

parts.Add(footer);
Console.WriteLine("WsscFooter added to " + web.Url);

}

//End Code Snippet

Any idea why this is not working?
Any help appreciated!

Regards,
Rickard
.



Relevant Pages

  • RE: DocLib WebPart and the ONET.XML file
    ... In the code snippet below: ... and give the webpart that BaseViewID ... >> identify the correct doc lib you want by the correct ...
    (microsoft.public.sharepoint.portalserver.development)
  • RE: Help with WebPartCollection
    ... when you create a new footer webpart, this webpart has another objectid than ... "Rickard" wrote: ... > //End Code Snippet ...
    (microsoft.public.sharepoint.portalserver.development)
  • Custom WebPart in MOSS 2007
    ... I am trying to create a webpart in MOSS 2007 beta 2. ... me the code snippet to create a webpart in MOSS 2007 which can show the ...
    (microsoft.public.sharepoint.portalserver)
  • Re: Create Alerts for Other Users
    ... I could use such a webpart for my users. ... but it's for WSS only:( ... with no support answers from Jan ... Prev by Date: ...
    (microsoft.public.sharepoint.portalserver)
  • Re: Hierachical list of favourite links?
    ... customise the view to be grouped by this filed. ... > WebPart that would allow me to do this? ... Prev by Date: ...
    (microsoft.public.sharepoint.windowsservices)