Click here to Skip to main content
Click here to Skip to main content

WPSC in MOSS 2007 - "Cannot retrieve properties at this time. "

, 24 Apr 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
How does WPSC register Web Parts differing from SharePoint 2003.

Introduction

Web Part Service Component (WPSC) is a nice feature for SharePoint developers working on client side programming. It supplies SharePoint Web Part objects combined with HTML objects for developers to practice on web part management.

Background

There seems not so much changes on the object level between SharePoint 2003 and SharePoint 2007. There is one more property in WPSC 3.0 than WPSC 2.0 called WebServerRelativeURL. But things seems not so simple because the way WPSC registers Web Parts has changed...

In WSS 2.0, WPSC registers a Web Part using tokens like WPQ1, WPQ2, WPQ3 ...

WPSC.Init(document);
var varPartWPQ7 = WPSC.WebPartPage.Parts.Register('WPQ7',
    '6b93d728-6d3e-47cb-9917-37cfd0aff443',document.all.item('WebPartWPQ7'));
var varPartWPQ3 = WPSC.WebPartPage.Parts.Register('WPQ3',
    '32950565-92aa-4a11-92b0-9dcff1b4e956',document.all.item('WebPartWPQ3'));
var varPartWPQ2 = WPSC.WebPartPage.Parts.Register('WPQ2',
    '338c0c38-b8cb-4ea2-918e-2d5c632df2bd',document.all.item('WebPartWPQ2'));
var varPartWPQ4 = WPSC.WebPartPage.Parts.Register('WPQ4',
    '3612bf7c-595c-48fe-aaf4-87cbb89078a2',document.all.item('WebPartWPQ4'));
var varPartWPQ5 = WPSC.WebPartPage.Parts.Register('WPQ5',
    '43bf7599-0acf-41d7-b3f5-397cbc7eca6b',document.all.item('WebPartWPQ5'));
var varPartWPQ6 = WPSC.WebPartPage.Parts.Register('WPQ6',
    '4623b8c7-989f-471c-a3fa-7f53148acdcd',document.all.item('WebPartWPQ6'));
var varPartWPQ1 = WPSC.WebPartPage.Parts.Register('WPQ1',
    '056d0533-514b-42e1-8925-38bf2c5b3b07',document.all.item('WebPartWPQ1'));

In WSS 3.0, WPSC registers a Web Part using the same tokens as WSS 2.0, but WPQ1 is used for register a null Web Part. If you try to access its properties, you will get an error: "Cannot retrieve properties at this time".

var varPartWPQ4 = WPSC.WebPartPage.Parts.Register('WPQ4',
    'e2412c24-1c4f-4545-93dc-2a4e965b2032',document.all.item('WebPartWPQ4'));
var varPartWPQ5 = WPSC.WebPartPage.Parts.Register('WPQ5',
    '77cbc2a3-c770-4a7d-9024-63b78cc45ff4',document.all.item('WebPartWPQ5'));
var varPartWPQ6 = WPSC.WebPartPage.Parts.Register('WPQ6',
    'f4481df0-a93d-495d-bcb6-fa686bbd9816',document.all.item('WebPartWPQ6'));
var varPartWPQ7 = WPSC.WebPartPage.Parts.Register('WPQ7',
    '1fddcba4-7b65-40d9-972f-d6ee86a224f4',document.all.item('WebPartWPQ7'));
var varPartWPQ1 = WPSC.WebPartPage.Parts.Register('WPQ1',
    '00000000-0000-0000-0000-000000000000',document.all.item('WebPartWPQ1')); 

Let's go through a sample code which will collect the Web Part titles:

if(typeof(WPSC) == 'undefined')
    return;
  
if(WPSC.WebPartPage)
    PortalPartsCollection = WPSC.WebPartPage.Parts; 
 
if(PortalPartsCollection) 
{ 
    for(var i=0; i< PortalPartsCollection.Count; i++) 
    { 
        var objWebPart = PortalPartsCollection.Item(i); 
    
        if(objWebPart.WebPartQualifier == "WPQ1")
            continue;
    
        if(objWebPart.Properties.Count() > 0)
        {  
            var webpartTitle = 
              objWebPart.Properties.Item("http://schemas.microsoft" + 
                                         ".com/WebPart/v2#Title").Value;
            PortalPartsTitleCollection.push(webpartTitle);
    
            var targetObject = searchTargetNode(objWebPart);
            if(targetObject)
            targetObject.innerHTML = createArchor(webpartTitle) + targetObject.innerHTML;
        }   
    } 
}

In the code above, we can see that the Web Part with WebPartQualifier "WPQ1" will be ignored.

History

This is the first version.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

David Meng
Web Developer MapleCity Consulting Inc.
Canada Canada
I am so happy to have the opportunity to share experience each other with you. Currently I am a web developer on sharepoint solutions. In this field I have developed many web parts for Toronto based organizations. Recently I have done one portal customization and upgrade it from WSS 2.0 to WSS3.0. I like sharepoint development. It brings me to the world of the collision between cutting edge techniques and traditional ways. I am enjoying the experience to know Microsoft wisdoms.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150414.1 | Last Updated 24 Apr 2008
Article Copyright 2008 by David Meng
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid