Thursday, January 19, 2012

Custom FormUrl s (Display, Edit & New) does not work for a custom content type

I was developing a custom list template with a custom content type. I had to implement our own custom forms for our custom content type (MyContentType). You can get how to add custom FormUrls for a content type from this MSDN documentation (http://msdn.microsoft.com/en-us/library/aa544142.aspx).

I did change the <FormUrls> in the custom content type definition as below. Even after I tried deploying quite a few times, it did not seems to take effect.

I was totally confused. After some struggle, I changed the inheriting content type to "Item" (0x0100) instead of "Post" (0x0110) content type, then the custom forms took the effect.



So, somehow it seems to me that some OOTB content types have display forms defined and it is not allowed to be overridden by our custom forms urls.

Happy coding
Senthil S

Wednesday, January 18, 2012

SPSiteDataQuery not returning all results when using ContentType filter

Recently, I was working on a case where all the SPListItems using a specific content type needs to be listed from the whole site collection. As you all know, SPSiteDataQuery is the way to go.

As I was getting to the end I noticed it was not returning all the items from the whole site collection. Instead it is returning only a few items, more like list items only from one particular list (weird!!! right) and no errors as well. If the same web part is added in some specific inner webs and tried to get all teh items from current web and all the sub webs the query works perfectly well. I was totally confused ...

After some researches, I came across this thread (http://social.technet.microsoft.com/Forums/en/sharepoint2010programming/thread/1294669a-546d-44f1-8b7d-6972bc11bc34) where it said the SPSiteDataQuery has some issues with filtering with "Computed" fields such as "ContentType" field. So I changed the filter from "ContentType" to "ContentTypeID" which f type "ContentTypeId" which seems to be working perfectly fine.

ContentType Filter:

<Where>
    <Eq>
        <FieldRef Name="ContentType" />
        <Value Type="Computed">My Content Type</Value>
    </Eq>
</Where>

ConteTypeId Filter:

<Where>
    <BeginsWith>
        <FieldRef Name="ContentTypeId" />
        <Value Type="ContentTypeId">My Content Type</Value>
    </BeginsWith>
</Where>

Above filter goes for the ".Query" attribute of the SPSiteDataQuery to filter by ContentType name and ContentTypeID respectively.

Hope this helps someone facing the same issue.

Thanks
Senthil S

Monday, January 9, 2012

Adding Metadata fields as View fields in Schema.xml does not capture values

Recently, I worked on creating a custom list definition from a custom content type. That was not a big deal with the awesome VS 2010. BUT, I faced an issue with one field (Enterprise Keywords) with capturing data selected in it.

I was using custom forms for the content type's Display, Edit and Delete forms. First I was thinking that I was doing something wrong with my custom forms. I changed the forms to default OOTB default list forms for that content type and deployed. But, even with the default forms also it was failing.

Then i found out if I remove the "Enterprise Keywords" column from the list fields (not the content type fields) and re-add the same, it was working fine.

After a long research, I found this blog (http://www.sharepointconfig.com/2011/03/the-complete-guide-to-provisioning-sharepoint-2010-managed-metadata-fields) which explained me about the list event receivers get added for capturing the Taxonomy Lookup fields.


After adding the above mentioned Item Event receivers based on the list template everything seemed to be working fine. Use the below elements.xml to add the above mentioned item event receivers.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListTemplateId="10002">
    <Receiver>
      <Name>TaxonomyItemSynchronousAddedEventReceiver</Name>
      <Type>ItemAdding</Type>
      <Assembly>Microsoft.SharePoint.Taxonomy, Version=14.0.0.0,
 Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
      <Class>Microsoft.SharePoint.Taxonomy.TaxonomyItemEventReceiver</Class>
      <SequenceNumber>10000</SequenceNumber>
    </Receiver>
    <Receiver>
      <Name>TaxonomyItemUpdatingEventReceiver</Name>
      <Type>ItemUpdating</Type>
      <Assembly>Microsoft.SharePoint.Taxonomy, Version=14.0.0.0, 
Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
      <Class>Microsoft.SharePoint.Taxonomy.TaxonomyItemEventReceiver</Class>
      <SequenceNumber>10000</SequenceNumber>
    </Receiver>
  </Receivers>
</Elements>

Just make sure the "ListTemplateId" matches with the "Type" attribute defined in the List Template definition .

Happy coding.
Senthil S

Wednesday, January 4, 2012

Using master page and layouts page in custom list view

I was struggling for couple of days now on how to make use of any master page in a layouts page which is used for a view of a custom list created using custom list schema.xml.

How to create a custom list definition is explained here (http://msdn.microsoft.com/en-us/library/ff728096.aspx)

I was able to create a custom list definition and added a custom list view page also in the schema.xml file itself. Here is how to add a custom list view using a layouts page (application page)

After adding a custom list schema, find the node "<Views>" and add a new "<View>" tag. You can just copy and paste the already existing "<View>" tag which has the BaseViewID="1" (this is the one which constitutes for the web page view. It is important that you should be copying the whole "<View>" node with all the internal elements like below.



To make use of the layouts page for the view, just change the "SetupPath" parameter to point to the corresponding layouts page without the "/" in front of the "layouts" folder (i.e., should be starting as "layouts/setup/settings.aspx") and change "Url" parameter to the name you want to see in the URL.

When I changed the "MasterPageFile" parameter to an application master page like below,

<%@ Page Language="C#" AutoEventWireup="true" 
                           MasterPageFile="~/_layouts/AppMasterPages/Simple.master" %>
 
the custom view gave me the below error

"The referenced file '/_layouts/AppMasterPages/Simple.master' is not allowed on this page"

If the "MasterPageFile" is change to "~masterurl/default.master", everything works well. If you are using a custom master page for the site you may make use of that by setting the "MasterPageFile" to "~masterurl/custom.master".

Happy coding.
Senthil S