How can i sort with xsl?

October 23rd, 2008 No Comments »

You can do sorting in xsl like this;

Also you can sort CKS EBE List’s like this:

This is sorting categories in a CKS:EBE List. I added a column to Sharepoint List: “Rank”, and sorted according to that.

<xsl:template match=”/”>
  <ul>
   <xsl:apply-templates select=”rows/row”>
   <xsl:sort select=”Rank” order=”ascending”/>
   </xsl:apply-templates>
  </ul>
</xsl:template>

 <xsl:template match=”row”>
  <li>
   <a href=”{ebe:createTagUrl(Title)}”>
    <xsl:value-of select=”Title”/>
   </a>
  </li>
 </xsl:template>

Getting CMSServerError in CmsHttpContext Current Searches GetByGuid method..

October 16th, 2008 No Comments »

I was getting CmsServerException (Microsoft.ContentManagement.Publishing.CmsServerException) saying  “ Server error.  Contact the site administrator. ”. when trying to call CmsHttpContext.Current.Searches.GetByGuid method.

 

It was hard to find out why this exception occurs, because there was no detail included.

 

Anyway I found out why;

 

I was calling the GetByGuid method like:

 

CmsHttpContext.Current.Searches.GetByGuid(myGuid.ToString());

 

Which was wrong…

 

When you make ToString() to a Guid, it does not return paranthesis of guid in the return string. On the other hand, GetByGuid wants its parameter string to have paranthesis.

 

 

It should be like:

 

CmsHttpContext.Current.Searches.GetByGuid(myGuid.ToString(“B”));

 

So that when you send the guid properly, you will get rid of CMSServerError..

Getting list items from a Sharepoint list by using Sharepoint Web Services

October 14th, 2008 3 Comments »
  • Ok, since we are trying to get Sharepoint list items via Sharepoint Web Services, we should add the web service then, as a reference to the project.

Adding Sharepoint web services as a web reference

The important point is; if you want to get listitems from a subsite’s list, don’t forget to change url like this;
For example;

Change url from;
http://<yoursite> /_vti_bin/Lists.asmx

To this;
http://<yoursite>/<yoursubsite> /_vti_bin/Lists.asmx

Otherwise, you can get a SoapException !

  • Set the credentials of the list.

List.Lists cl = new List.Lists();

System.Net.NetworkCredential cred = new System.Net.NetworkCredential(
                    listUser,
                    listPwd);

cl.Credentials = cred;

cl.Url = ConfigurationManager.AppSettings["List.Lists"];

  • Write a caml query to filter results. (you can look at caml query example from this posting.) (Or don’t write any query if you want to get whole items in the list)

System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlNode whereQuery = xmlDoc.CreateElement(”Query”);

whereQuery.InnerXml = String.Format(”<Where>{0}</Where>”,”write a caml query like the one in the that posting”);

  • You can get list items by calling GetListItems method.

XmlNode listNodes = cl.GetListItems(”LISTNAME”, null, whereQuery, null, null, null, null);

  • We have an xml which contains all items. But in order to get only items you should select nodes under “//rs:data/z:row”.
  • First I had tried to select nodes under “//rs:data”. But the child count is doubled, because between each child there exists a node of Whitespace (\n). So in order to get list items properly, “z:row” nodes should be selected.

XmlNamespaceManager nm = new XmlNamespaceManager(listNodes.OwnerDocument.NameTable);
nm.AddNamespace(”rs”, “urn:schemas-microsoft-com:rowset”);
nm.AddNamespace(”z”, “#RowsetSchema”);
XmlNodeList nodes = listNodes.SelectNodes(”//rs:data/z:row”, nm);

  • To display Sharepoint listItems in a repeater, bind the XmlNodeList to the repeater, and configure the template of repeater in the aspx.

<asp:Repeater ID=”rptList” runat=”server”>

     <ItemTemplate>

            <table>

                <tr>

                    <td colspan=”2″>

                        <%# ((XmlNode)Container.DataItem).Attributes["ows_Title"].Value%>

                    </td>

                </tr>

                <tr>

                    <td align=”left”>

                        <%# ((XmlNode)Container.DataItem).Attributes["ows_Date"].Value%>

                    </td>

                    <td align=”right”>

                        <%#  ((XmlNode)Container.DataItem).Attributes["ows_Place"].Value%>

                    </td>

                </tr>

               </table>

         </ItemTemplate>

</asp:Repeater>

 

CAML Queries..

October 12th, 2008 No Comments »

I’ll let my first post be about CAML queries in Sharepoint…

I was trying to write Caml Query to retrieve list items from Sharepoint, so I decided to write a post about that. First; Operators in Caml Queries are;

  • Eq                           Equals
  • Neq                        Not equal
  • Gt                           Greater than
  • Ge                           Greater than or equal
  • Lt                            Lower than
  • Le                           Lower than
  • IsNull                    Is null
  • BeginsWith         Begins with
  • Contains              Contains

Here comes a simple query, which can get list items whose FieldA property is equal to ChoiceB;

<Where>

<Eq>

<FieldRef Name=”FieldA” />

<Value Type=”Choice”>ValueB</Value>

</Eq>

 </Where>  

 

 You can add as many filters as you like by using And or Or. And lets compare Date values now;

<Where>

                <And>

<Leq>

<FieldRef Name=”FieldStartDate” />

<Value Type=”DateTime” IncludeTimeValue=”False”>

<Today/>

</Value>

</Leq>

<Geq>

<FieldRef Name=”FieldEndDate” />

<Value Type=”DateTime” IncludeTimeValue=”False”>

<Today/>

</Value>

</Geq>

</And>

</Where>

 

You can use <Today/> to give today’s date. Or you can use <Now/> if you want to also take time part account.

By the way, you can use something like <Today OffsetDays=”+3” /> if you want to say 3 days after today.

To get previous days use (-) (negative numbers), or to get next days use (+) (positive numbers)

I searched but could not find something like OffsetMonths, if you know, please let me know.

Also I should say, one of the common mistakes, I am always doing; writing more than 2 statements inside an “And” or “Or”. You should not write more than 2 statements!

Just write it like;

 

<Where>

                <And>

                <And>

<Leq>

…..

</Leq>

<Geq>

…..

</Geq>

</And>

<Geq>

…..

</Geq>

</And>

</Where>

 

<OrderBy>

<FieldRef Name=”FieldA” Ascending=”True”/>

</OrderBy>

Take a look at my final CAML query; (just as an example) 

 

 

<Query>

<Where>

<And>

<Eq>

<FieldRef Name=”FieldA” />

<Value Type=”Choice”>ChoiceA</Value>

</Eq>

<Or>

<Or>

<And>

<Geq>

<FieldRef Name=”FieldStartDate” />

<Value Type=”DateTime” IncludeTimeValue=”False”>

<Today/>

</Value>

</Geq>

<Leq>

<FieldRef Name=”FieldStartDate” />

<Value Type=”DateTime” IncludeTimeValue=”False”>

<Today OffsetDays=”+10″ />

</Value>

</Leq>

</And>

<And>

<Geq>

<FieldRef Name=”FieldEndDate” />

<Value Type=”DateTime” IncludeTimeValue=”False”>

<Today />

</Value>

</Geq>

 

 

<Leq>

<FieldRef Name=”FieldEndDate” />

<Value Type=”DateTime” IncludeTimeValue=”False”>

<Today OffsetDays=”+10″ />

</Value>

</Leq>

</And>

</Or>

<And>

<Leq>

<FieldRef Name=”FieldStartDate” />

<Value Type=”DateTime” IncludeTimeValue=”False”>

<Today />

</Value>

</Leq>

<Geq>

<FieldRef Name=”FieldEndDate” />

<Value Type=”DateTime” IncludeTimeValue=”False”>

<Today OffsetDays=”+10″ />

</Value>

</Geq>

</And>

</Or>

</And>

</Where>

<OrderBy>

<FieldRef Name=”FieldStartDate” Ascending=”True” />

</OrderBy>

</Query>

 

 

Found out that there is a CAML Builder tool, you can check that out from this site