Monday, January 24, 2011

How to get all items of Discussion Board list using Web Service.

Hello everybody,
I am working on Discussion Board list using Web Service. I am so supprised that the DB list is not the same as another list in SharePoint. The first sign of my mind is Calendar List Item, SharePoint stores the StartDate & EndDate with a different ways. To get the correctly data, we must understand clearly about architecture of Calendar list.

For now, the problem about Calendar was solved and faced to another problem. Discussion Board list has 2 item types: Dicussion (threads) and Message (replies). When you get all items by normaly, you only get the discussion items, take a look at code:


            XmlDocument document = new XmlDocument();
            XmlNode query = document.CreateNode(XmlNodeType.Element, "Query", "");
            
            XmlNode viewFields = document.CreateNode(XmlNodeType.Element, "ViewFields", "");


            XmlNode queryOptions = document.CreateNode(XmlNodeType.Element, "QueryOptions", "");
            queryOptions.InnerXml = "<ViewAttributes Scope='RecursiveAll'/>";


            Lists lists = new Lists(URL_SERVER);
            lists.Credentials = CredentialCache.DefaultCredentials;
            
            XmlNode node4 = lists.GetListItems(sourceList, "", query, viewFields, "", queryOptions);


Okey, even thought Scope attribute is set to "RecursiveAll", and SharePoint 2007 works fine. All items including reply items are list. But it does not work in SharePoint 2010, so it is not actually difficult to fix for SharePoint 2010. Just update your query CALM like the code below:


query.InnerXml = @"<Query>
                                <Where>
                                    <Geq>
                                        <FieldRef Name=""DiscussionLastUpdated"" />
                                        <Value Type=""DateTime"">1900-01-01T00:00:00Z</Value>
                                    </Geq>
                                </Where>
                               </Query>";
Yes, that's it.

Sunday, January 23, 2011

Show friendly error in SharePoint

Sometime, i dont know why my webpart (or site/page) happens error, event thought i turned off the CustomError tag in Web.Config

<CustomError mode="Off"/>

The default vallue of Mode is "ON", that means, SharePoint will show the error page liek this:

We've never known what about this error and also in the code there are any functions/methods give this issue. So, to let SharePoint show friendly the error and the stack trace of this error, we must change some values/attribute of tag in web.config.

1) Set Mode of <customerror> is Off

<CustomError mode="Off"/>

2) Find the tag <combilation> and change the value of debug is True

<compilation batch="false" debug="true">

3) In <SharePoint> tag, change the attributes of <SafeMode> to be:

<SafeMode MaxControls="200" CallStack="true" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="true">


Remember that doing reset IIS before press F5.


Now you can see your error as details and it's very easy to fix.