How to add Web Analytics WhatsPopular web part prgrammatically in web part page SharePoint 2010


  • I can't find any way to add web analytics (WhatsPopular) web part class in SharePoint 2010 development. Please let me know how to add this webpart in webpart page programmatically.


    Shamshad Ali
    Tuesday, March 22, 2011 11:03 AM

All replies

  • Hi,

    look for SPUsageReceiver.


    Daniel Bugday
    Microsoft Community Contributor, Member of Microsoft Extended Expert Team, MCT, MCTS, MCDBA, MCSE, MCC

    Blog: SharePoint By Bugday
    Twitter: Follow me on Twitter
    Technet: My Ask The Exert Area On Technet
    Founder of SharePoint Forum

    Tuesday, March 22, 2011 1:57 PM
  • Hi Daniel,

    Thanks for your reply. I am using following code to add an image webPart programmatically. Could you plz. share the code how do i do add WhatsPolular webpart by following sample code:

            using (SPSite site = new SPSite(SPSiteURL))
            using (SPWeb web = site.AllWebs[websiteName])
              ImageWebPart ImageWp = new ImageWebPart();
              ImageWp.ImageLink = "/VID/VidPages/scripts/logo_vid.png";
              ImageWp.VerticalAlignment = VerticalAlignment.Middle;
              //ImageWp.HorizontalAlign = HorizontalAlignment.Left;
              ImageWp.AllowClose = false;
              ImageWp.AllowMinimize = false;
              ImageWp.AllowHide = false;
              ImageWp.AllowZoneChange = false;
              ImageWp.AllowEdit = false;
              ImageWp.ChromeType = PartChromeType.None;
              ImageWp.ZoneID = "RightColumn";
              webpartMgr.AddWebPart(ImageWp, ImageWp.ZoneID, 0);


    Shamshad Ali
    Tuesday, March 22, 2011 2:42 PM
  • Hi Shamshad,

    I didn't find any build-in 'WhatsPolular' web part you mentioned.

    If you had the web part, you can create a instance of the web part and set properties's value for the instance and add it to WebPartManager.

    In fact it is nearly the same with the procedure to add image web part you posted.

    Microsoft Online Community Support
    Wednesday, March 23, 2011 5:22 AM
  • Hi KeFang,

    I have the webpart from UI, Web Analytics (WhatsPopular) but I am unable to create its intance. That is what I am asking for. Please help.


    Shamshad Ali
    Thursday, March 24, 2011 5:31 AM
  • Hi

    I just added the WebAnalytics web part to a page and checked the code view of the page in the SharePoint designer

    The WhatsPopularWebPart seems to be in the Microsoft.Office.Server.WebAnalytics.Reporting namespace.

    Try adding a reference to this and check if you can use the same code above by replacing the  ImageWebPart with WhatsPopularWebPart.

    Thursday, March 24, 2011 7:33 AM
  • Hello Naveed,

    Thanks for sharing the trick how to get the class library name of existing webpart added through UI. I am unable to find this class from C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\

    I am able to add other libraries such as Microsoft.Office.Server.dll, Microsoft.Office.Server.Search.dll, Microsoft.Office.Server.UserProfiles.dll

    I also searched system for this name and found Microsoft.Office.Server.WebAnalytics.Components namespace in C:\Program Files\Microsoft Office Servers\14.0\Bin\Microsoft.Office.Server.WebAnalytics.Components.dll folder and added in project code, but it has ReportConsolidator NOT Reporting as you mentioned above.

    Please help.

    Shamshad Ali
    Friday, March 25, 2011 5:30 AM
  • Hi

    Add a Reference to the Microsoft.Office.Server.WebAnalytics.UI.dll

    I spotted it here C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Server.WebAnalytics.UI\\Microsoft.Office.Server.WebAnalytics.UI.dll

    Go to Add Reference and browse to this location.

    Then add using Microsoft.Office.Server.WebAnalytics.Reporting;

    Friday, March 25, 2011 6:39 AM
  • Thanks Naveed, Your help is highly appreciated. One last thing to complete the webpart, I need the name of property which is used for "Information to Display" and its value i.e. "Most frequest search center queries". Please let me know how do i set this property for WhatsPopular webpart.

    I would appreciate your help.

    Shamshad Ali
    Monday, March 28, 2011 5:22 AM
  • Hi

    I followed the same procedure as mentioned above. Added the web part, changed the property and checked the difference in the SharePoint designer.

    It turned out to be the View property for the web part.

    Set the View property for your web part and let me know if it works

    WhatsPopularWebPart wp = new WhatsPopularWebPart();
    wp.View = WhatsPopularType.SearchCenterQueries;

    Monday, March 28, 2011 7:22 AM
  • Yes, True Naveed. Thanks again. I am getting error when adding this webpart with following code:

             WhatsPopularWebPart whatsPopularWp = new WhatsPopularWebPart();
             whatsPopularWp.Title = "Top Searches";
             whatsPopularWp.Description = "Displays the most viewed content, most frequent search queries from a site, or most frequent search queries from a search center.";
             whatsPopularWp.ShowPopularityRank = true;
             whatsPopularWp.ShowFrequency = true;
             whatsPopularWp.ShowPopularityTrend = false;
             whatsPopularWp.EnableRSSFeed = false;
             whatsPopularWp.EnableUserTitleFiltering = false;
             whatsPopularWp.EnableUserDeptFiltering = false;
             whatsPopularWp.SearchScope = SearchScope.Subtree.ToString();
             whatsPopularWp.ChromeType = PartChromeType.TitleOnly;
             whatsPopularWp.View = WhatsPopularType.SearchCenterQueries;
             whatsPopularWp.ItemLimit = 10;
             whatsPopularWp.AllowClose = false;
             whatsPopularWp.AllowHide = false;
             whatsPopularWp.AllowMinimize = false;
             whatsPopularWp.AllowZoneChange = false;
             whatsPopularWp.AllowEdit = false;
             //whatsPopularWp.ZoneID = "LeftColumn";
             webpartMgr.AddWebPart(whatsPopularWp, "LeftColumn", 3);

    I got following error:

    ***** ERROR *****
    There was an error generating the XML document.
    System.InvalidOperationException: There was an error generating the XML document. ---> System.NullReferenceException: Object reference not set to an instance of an object.
       at Microsoft.Office.Server.WebAnalytics.Reporting.WhatsPopularWebPart.get_EnableRSSFeed()
       at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterWhatsPopularWebPart.Write12_WhatsPopularWebPart(String n, String ns, WhatsPopularWebPart o, Boolean isNullable, Boolean needType)
       at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterWhatsPopularWebPart.Write13_WebPart(Object o)
       --- End of inner exception stack trace ---
       at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
       at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o)
       at Microsoft.SharePoint.WebPartPages.WebPart.WriteXmlAsBytes(XmlSerializer xmls)
       at Microsoft.SharePoint.WebPartPages.BinaryWebPartSerializer.Serialize(PersonalizationScope scope)
       at Microsoft.SharePoint.WebPartPages.BinaryWebPartSerializer.get_Links()
       at Microsoft.SharePoint.WebPartPages.SPWebPartManager.AddWebPartToStore(WebPart webPart, Int32 viewId, String viewGuid)
       at Microsoft.SharePoint.WebPartPages.SPWebPartManager.AddWebPartInternal(SPSupersetWebPart superset, Boolean throwIfLocked)
       at Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager.AddWebPartInternal(WebPart webPart, String zoneId, Int32 zoneIndex, Boolean throwIfLocked)
       at Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager.AddWebPart(WebPart webPart, String zoneId, Int32 zoneIndex)
       at SharePoint2010Installer.InstallProcessControl.SolutionCommand.CreateVidizmoHomePage() in C:\Projects\SharepointIntegration\VS2010\SharePointSolutionInstaller\Source\InstallProcessControl.cs:line 796
       at SharePoint2010Installer.InstallProcessControl.CreateWebpartpagesInDocumentLibraryCommand.Execute() in C:\Projects\SharepointIntegration\VS2010\SharePointSolutionInstaller\Source\InstallProcessControl.cs:line 4071
       at SharePoint2010Installer.InstallProcessControl.TimerEventInstall(Object myObject, EventArgs myEventArgs) in C:\Projects\SharepointIntegration\VS2010\SharePointSolutionInstaller\Source\InstallProcessControl.cs:line 116


    Shamshad Ali
    Monday, March 28, 2011 12:52 PM
  • Using ULS I am getting following error:

    Failed to look up string with key "FSAdmin_SiteSettings_UserContextManagement_ToolTip", keyfile Microsoft.Office.Server.Search.

    Localized resource for token 'FSAdmin_SiteSettings_UserContextManagement_ToolTip' could not be found for file with path: "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\Template\Features\SearchExtensions\ExtendedSearchAdminLinks.xml".

    Error initializing Safe control - Assembly:Microsoft.Office.SharePoint.ClientExtensions, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c TypeName: Microsoft.Office.SharePoint.ClientExtensions.Publishing.TakeListOfflineRibbonControl Error: Could not load type 'Microsoft.Office.SharePoint.ClientExtensions.Publishing.TakeListOfflineRibbonControl' from assembly 'Microsoft.Office.SharePoint.ClientExtensions, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.

    Please help.

    Shamshad Ali
    Wednesday, March 30, 2011 5:01 AM