How can I get a Content Query Web Part to show items from more than one type of list? - sharepoint

I am trying to use a Content Query Web Part to create a "What's New" page in Sharepoint 2010. The goal of this page is to display any documents that have been uploaded in the last 14 days. The trick is that these documents could belong to any number of lists that are defined in any number of list definitions. These are custom list definitions based on custom content types. We do have a base content type that each of our custom content types inherit from. They are also all part of the same content type group. I have determined that it is not possible to use the SP UI to set up the CQWP to return items from multiple list types, since one of the required query fields is list type. So - I'm attempting to use CAML to define this CQWP and this is where I'm having trouble. My end goal is for the CAML to be defined in a site definition (onet.xml file) but I've also not had any luck with uploading a .webpart file from the SP UI. I have found several articles that explain how this should be done but haven't been able to get the suggested solutions to work. This MSDN article tells me it should be possible using the ListsOverride element. This is how the article tells me to do it:
<![CDATA[
<Lists BaseType="0">
</Lists> ]]>
Since I'm looking for Document Libraries I would use a base type of 1 rather than 0.
I have been unable to determine the syntax for what that would actually look like from within the onet.xml file so I thought I'd start with trying to get it uploaded as a .webpart file.
This is what the ListsOverride element looks like:
<property name="ListsOverride" type="string">
<![CDATA[<Lists BaseType="1"></Lists>]]>
</property>
However - as soon as I upload a .webpart file with this in the CAML and add the webpart to a page I break that page in Sharepoint. This is what I get:
Server Error in '/' Application.
Attempted to use an object that has ceased to exist.
Research on that error points me to code that disposes of an object such as SPContext.Current.Web but I don't even have any code at all here. It almost looks like the CQWP has a bug in it. OR - I'm either not formatting that CAML properly or maybe I need to change something in a different element in the CAML?
I am running Sharepoint 2010 SP1 with all the latest patches. (I believe)
I've tried several other formats but without luck.
I tried getting rid of the embedded CDATA tags like this:
<property name="ListsOverride" type="string">
<Lists BaseType="1"></Lists>
</property>
But then Sharepoint won't let me upload the .webpart file. (Invalid .webpart file)
The format with the embedded CDATA tags seems to be the only way it lets me upload the file.
I've tried (just for the sake of narrowing down my issue) to specify specific lists like this:
<property name="ListsOverride" type="string">
<![CDATA[<Lists><List Id="{5a2f79bb-cc82-4171-88ac-65f20e7b5fa8}" /></Lists>]]>
That doesn't break the page but the webpart gives me less than useful error on the page (Unable to display this Web Part)
I'm not 100% sure that I used the appropriate GUID in that attempt. I got it from looking in the server explorer in Visual Studio (Under Lists and Libraries >> Document Libraries >> My List Type. (I got the GUID from the Id property)
I should mention that I am fairly new with Sharepoint development. I would have hoped that something seemingly so core to what Sharepoint does would be much easier than this.
Can someone please point out what I am doing wrong? Maybe I'm going about the whole thing in the wrong way? I appreciate any help that anyone can give me!

I found that the issue was all the "extra" fields that SharePoint had populated.
In my case, I started by configuring the content query web part on the page and then exporting it to get the xml. Then, I put the XML in my onet.xml file of my site definition. That worked fine initially, but as I tried to configure the base types, it did not behave as expected.
If I removed all the additional fields and just used the few fields that I actually needed to configure, then it started to work. In fact, I didn't even need to use the ListsOverride element, since there is a BaseType property that works just fine. It appears that one of the other properties that I was pulling in was really the cause of my issues.
Here's a webpart definition that I used in my onet.xml:
<AllUsersWebPart WebPartZoneID="WebPartZone" WebPartOrder="1">
<![CDATA[
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart, Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="Title" type="string">Recently Updated Documents</property>
<property name="ChromeType" type="chrometype">TitleOnly</property>
<property name="ChromeState" type="chromestate">Normal</property>
<property name="WebUrl" type="string">~site</property>
<property name="BaseType" type="string">1</property>
<property name="ContentTypeBeginsWithId" type="string">0x0101008B0856395DCD40F99C9B42B6BF92BDDB</property>
<property name="FilterField1" type="string">{28cf69c5-fa48-462a-b5cd-27b6f9d2bd5f}</property>
<property name="FilterType1" type="string">DateTime</property>
<property name="FilterOperator1" type="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+FilterFieldQueryOperator, Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">Geq</property>
<property name="FilterDisplayValue1" type="string">-14</property>
<property name="FilterValue1" type="string">-14</property>
<property name="SortBy" type="string">{8c06beca-0777-48f7-91c7-6da68bc07b69}</property>
<property name="SortByFieldType" type="string">DateTime</property>
<property name="SortByDirection" type="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+SortDirection, Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">Desc</property>
<property name="ItemXslLink" type="string">~sitecollection/Style Library/DealerPortal/ItemStyle.xsl</property>
<property name="CommonViewFields" type="string">Name,Text;Created,DateTime;Modified,DateTime;Body,Note;DocumentIconImageUrl;OnClickForWebRendering</property>
</properties>
</data>
</webPart>
</webParts>
]]>
</AllUsersWebPart>

Related

Hybris - Adding new column in cscockpit search result

I am customizing the cscockpit for a module Order Search. Presently it shows three fields in the Order Search Result list. This setting is configured in a CockpitGroup.xml file named Order_OrderSearchResult_CockpitGroup.xml (Location: hybris\bin\ext-channel\cscockpit\resources\cscockpit\import\config)
My customized project is at location: hybris\bin\custom
How should I make a custom file of existing CockpitGroup.xml to include my new field?
The contents of Order_OrderSearchResult_CockpitGroup.xml are as below:
<?xml version="1.0" encoding="UTF-8"?>
<list-view unassigned-group-name="Other">
<group name="General">
<property qualifier="Order.creationtime" visible="true"/>
<property qualifier="Order.code" visible="true"/>
<property qualifier="Order.salesApplication" visible="true"/>
</group>
</list-view>
I want to add a new field Order.downloadDate.
I'm assuming you are not asking how to add <property qualifier="Order.downloadDate" visible="true"/> to that xml, and are asking instead how to configure the use of your customised file.
Look at the examples in "projectdata_cscockpit_ui_components.impex" delivered with the yacceleratorcockpits template. This will form part of your Accelerator project after modulegen.

SharePoint Search + BCS and meaningless non-human-readable urls

Indexing an external content type is pretty straight forward.
However I find it very troublesome to figure out the specific "crawl state" of a particular item.
Looking at the "Url View" inside SharePoint CA it shows me all my crawled/indexed items. Unfortunately the url part is nowhere near readable. So I have no clue where to look for my specific item in question.
Example:
bdc3://adventureworksdbtest/Default/00000000%2D0000%2D0000%2D0000%2D000000000000/418/AdventureworksDB/420?s_id=i0QMAAA==&s_ce=0408808680g000g10204000g0o20003s
Guid.Empty?
418?
420?
Some encoded id? (it's not BASE64. i0QMAAA== translates to nothing).
The AdventureWorks product table has a productID (int) and a name (string). In my BDC model I mapped the "Title" column to the product's "Name" column for my Product entity. See below...
<Entity Name="Product" Namespace="Rs.Exp.IndexingConnector.BuiltinDbConnector" Version="1.0.0.1">
<Properties>
<Property Name="OriginalName" Type="System.String">[Production].[Product]</Property>
<Property Name="EntitySetName" Type="System.String">[Production].[Product]</Property>
<Property Name="Title" Type="System.String">Name</Property>
</Properties>
<Identifiers>
<Identifier Name="ProductID" TypeName="System.Int32" />
</Identifiers>
<!-- [...] -->
</Entity>
That's working. However it has no influence on the "index url". Any hints? Something I have to live with? How do you debug this?
Update: DisplayUriField sounds like a good thing to look into. Although all I found so far is not what I am looking for. I'm not looking for a way to provide an url myself (where would I link to anyway?!) - I just want the "generated url" to be more meaningful.
Answering my own question in case anyone else is wondering how this works.
The Method(Instance) Property "DisplayUriField" is in fact providing the desired functionality. As a value you can set the name of a TypeDescriptor which is part of your entity schema.
For example if you have a TypeDescriptor like the one below (make sure your SELECT statement returns the column in question)...
<TypeDescriptor Name="Url" TypeName="System.String">
<Properties>
<Property Name="ShowInPicker" Type="System.Boolean">false</Property>
</Properties>
</TypeDescriptor>
...you can use it as a value for your DisplayUriField property:
<MethodInstances>
<MethodInstance Name="GetAllProducts" Type="Finder" ReturnParameterName="GetAllProducts_Returned" Default="true" DefaultDisplayName="Get All Products">
<Properties>
<Property Name="RootFinder" Type="System.String">x</Property>
<Property Name="LastModifiedTimeStampField" Type="System.String">ModifiedDate</Property>
<Property Name="DisplayUriField" Type="System.String">Url</Property>
</Properties>
</MethodInstance>
</MethodInstances>
My Database Table Url column contains urls like this
http://localhost/adventurworks/catalog/1
http://localhost/adventurworks/catalog/316
http://localhost/adventurworks/catalog/317
[...]
Whatever is in your column will be shown in SharePoints Crawl Log ("Url View").
If your column ("Url") is nullable and does not contain any value BDC will use a default name for that specific item.
Of course after all the custom url is pretty damn useless. However it allows me to figure out whether one specific item has been crawled (successfully) or not because I can relate the shown Url to the ProductID - which I cannot with those bdc3:// urls.

WhatsPopularWebPart as delegate control

I want to add the WhatsPopularWebPart as a delegate control. Registered a controlid in the masterpage and created a feature with this XML-manifest:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Control ControlAssembly="Microsoft.Office.Server.WebAnalytics.UI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" ControlClass="Microsoft.Office.Server.WebAnalytics.Reporting.WhatsPopularWebPart" Id="WebAnalyticsDelegate" >
<Property Name="Title">Most viewed pages</Property>
<Property Name="DateRange">SevenDays</Property>
<Property Name="ItemLimit">6</Property>
</Control>
However, the webpart keeps saying "Loading". I think the callback is not executed. When I look at the HTML, the WebPartId is only zeroes (0000-00000-00 etc.) instead of a valid GUID. Perhaps that is the problem?
I want to add the webpart to every page on the site, therefore using delegate controls.
Hum...
I don't see why it is not working. See this link :
http://blog.brianfarnhill.com/2008/12/08/using-the-delegate-control-to-deploy-a-web-part-through-features/
Maybe it is a problem with This particular webpart : http://social.msdn.microsoft.com/Forums/en/sharepoint2010general/thread/93782f9c-b582-436c-8c66-12349fd752b2
Have you tried with other webpart ?
Solution: ContentPlaceHolder in masterpage and in every page layout a webpart zone in that ContentPlaceHolder. Further in the provisioning of the pagelayout an with the webpart definition of the WhatsPopularWebPart. Problem solved.

What is the difference between the "Path" and "SetupPath" attibutes on the Module element

So I have a SharePoint feature definition that deploys page layouts to a publishing site. The definition looks something like this:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="Page Layouts" Url="_catalogs/masterpage" RootWebOnly="True">
<File Path="Page Layouts\layout1.aspx" Url="layout1.aspx" Type="GhostableInLibrary" IgnoreIfAlreadyExists="True">
<Property Name="Title" Value="Layout 1" />
<Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
</File>
</Module>
</Elements>
The Module element also can accept the attributes "Path" and "SetupPath." My understanding is that if these two attributes are omitted then SharePoint looks for layout1.aspx in the same folder as this feature, if Path is specified then SharePoint looks for the file in a path relative to this features' folder and if SetupPath is specified SharePoint looks for the file relative to the 14 Hive.
So is this basic understanding correct? Once the feature is activated and live on the site, would this layout page be stored or handled any differently had I specified Path or SetupPath? Would load time of the layout file be in any way affected?
Thanks,
Greg
To extend on what ashish mentioned.
Path = path relative to WSS 12 hive Features\Feature folder
SetupPath = path relateive to WSS 12 hive Template folder.
Please check following documentation in SharePoint SDK: http://msdn.microsoft.com/en-us/library/ms434127.aspx

Only one web part added to the wp gallery when multiple webpart files specified in module

I'm trying to deploy multiple web parts as part of the same feature. SharePoint itself seems to do this quite happily by specifying multiple File elements in a single Module element (see C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\SearchWebParts); in my case, only the first web part is added to the Web Parts gallery, albeit to the Miscellaneous group instead of the group specified in the Property element.
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="WebPartPopulation" Url="_catalogs/wp" Path="WebParts">
<File Url="Test1.webpart" Type="GhostableInLibrary">
<Property Name="Group" Value="MyGroup" />
</File>
<File Url="Test2.webpart" Type="GhostableInLibrary">
<Property Name="Group" Value="Mygroup" />
</File>
</Module>
</Elements>
My .webpart files are located in the same directory as the elements file; I tried setting Path="" on the Elements element but nothing gets deployed then. Switching around the two File elements deploys Test2.webpart instead of Test1 and Test1.webpart is not added on feature activation. Adding a single File per Module does work but that means duplicating the Module elements.
I'm self-closing the Property elements but that's surely not a sin?? What am I doing wrong?
The above would seem to be correct: after a reboot and a sleep, both web parts ended up in their proper groups when I came back to it the next day. It's surprising how often I find a reboot fixes up weird SharePoint things like this that even and iisreset won't touch. Maybe other services that should be reset/caching these things?

Resources