Category Archives: sharepoint

SharePoint SPDataSource

Tired of writing codes and creating webparts? Here is a less code solution for SharePoint developers.

The SPDataSource control (Microsoft.SharePoint.WebControls.SPDataSource) means a lot to developers.

With less custom code one can quickly retrieve and display data from SharePoint lists and libraries.

This is how you can access list data from SharePoint. For select command you can use CAML query builder from U2U.

This data source can be used like a SQL data source which comes with standard asp.net controls.

<SharePoint:SPDataSource ID=”spdsSupervisor” runat=”server” DataSourceMode=”List” SelectCommand=”<Query><Where><Eq><FieldRef Name=’Heading’ /><Value Type=’Choice’>Questions</Value></Eq></Where></Query>”>
<SelectParameters>

<asp:Parameter Name=”ListName” DefaultValue=”Feedback”/>

</SelectParameters>
</SharePoint:SPDataSource>

For data binding to any data bound controls this data source can be used. Given below is an example of using Data source with an asp grid view.

<asp:GridView runat=”server” id=”gvSupervisor” AutoGenerateColumns=”False” DataSourceID=”spdsSupervisor”
GridLines=”None” ForeColor=”#333333″ CellPadding=”4″ width=”100%”>

<FooterStyle BackColor=”#e2eeff” Font-Bold=”True” ForeColor=”White” />

<RowStyle BackColor=”#EFF3FB” Font-Size=”Smaller”/>

<Columns>

<asp:boundfield DataField=”Title” HeaderText=”Type” HeaderStyle-Font-Bold=”true” HeaderStyle-Font-Names=”verdana” HeaderStyle-ForeColor=”#525252″
HeaderStyle-HorizontalAlign=”Left”>

</asp:boundfield>

<asp:templatefield HeaderText=”Rating”
FooterStyle-HorizontalAlign=”Left”
HeaderStyle-Font-Bold=”true”
HeaderStyle-Font-Names=”verdana”
HeaderStyle-ForeColor=”#525252″
ItemStyle-HorizontalAlign=”Right”>

<ItemTemplate>

    <asp:RadioButtonList runat=”server” id=”rblCourse”
RepeatDirection=”Horizontal” CssClass=”ms-radiotext”>

        <asp:ListItem>1</asp:ListItem>

        <asp:ListItem>2</asp:ListItem>

        <asp:ListItem>3</asp:ListItem>

        <asp:ListItem>4</asp:ListItem>

        <asp:ListItem>5</asp:ListItem>

        <asp:ListItem>N/A</asp:ListItem>

    </asp:RadioButtonList>

</ItemTemplate>

</asp:templatefield>

</Columns>

<PagerStyle HorizontalAlign=”Center” BackColor=”#2461BF”
ForeColor=”White” />

<SelectedRowStyle BackColor=”#D1DDF1″ Font-Bold=”True”
ForeColor=”#333333″/>

<HeaderStyle BackColor=”#e2eeff” Font-Bold=”True”
Font-Size=”Large” ForeColor=”White” />

<EditRowStyle BackColor=”#2461BF”/>

<AlternatingRowStyle CssClass=”ms-alternating”
BackColor=”White”/>

</asp:GridView>

The above code will result in a grid looking like below. I have used some SharePoint CSS (Core.css) to bring the SharePoint look.

The data should be displayed using bound columns. The SPDataSource can be used with SharePoint controls without any coding.

Given below is another example for binding data to InputFormCheckBoxList in SP.

<sharepoint:InputFormCheckBoxList ID=”InputFormCheckBoxList1″ runat=”server”
CssClass=”ms-authoringcontrols”
DataSourceID=”spdsSupervisor” DataTextField=”Title”/>

The above code will result in a checkbox list looking like the one below. On change of codes the assemblies need not be recompiled and deployed

To GAC. This means no building of WSP/CAB files and writing codes to copy assemblies to Global Assembly Cache. (Nice isn’t it)

Hassle free code with fewer bugs can be developed by using SPDataSource. There are different types of Datasourcemode-ListItem, CrossList, Webs, and ListOfLists.

SharePoint developers who develop applications and custom application pages with SharePoint as data store (Lists as tables) will be benefited by using SPDataSource.

SharePoint List – Column name

Column names in SharePoint lists, doesn’t changes internally while modifying. Rather it changes the name in view alone. (SQL table as list & views as user views). Whenever we access the list item value programmatically, the display name is used to refer the field.

SPList li=new SPList();

SPItem item =li.Items[0];

item.Fields[strdisplayname].GetFieldValue();

But in some cases like adding event receiver to the list the internal name o f the field name (Underlying name) is used. It can be found by right clicking the column name and noting the url.

http://xxx/Docs/_layouts/FldEdit.aspx?List=%7B7B782235%2DDBCC%2D49D1%2D907E%2D85F3C434CA47%7D&Field=Status

The name might sometime look like Database_x0020_Name which need to be xml decoded at time of programming. Use xml decoding like this

XmlConvert.DecodeName(properties.ListItem.Fields[“Fieldname”].StaticName)

Happy programming.

Sharepoint server licensing

While searching for moss installation in farm scenario I came across multiple suggestions. Apart from standalone installation while making a vanilla implementation it’s easy…When going for moss implementation with both intranet and extranet users it becomes tedious.

Here are the software requirements and licensing details for the scenario

 

 

  • Windows Server 2003 R2 Enterprise Edition.
  • Office SharePoint Server 2007 Enterprise edition..
  • Office SharePoint Server 2007 Enterprise CAL.
  • MOSS Internet Connector CAL
  •  Microsoft SQL Server 2005 SP1 or later.
  • MS Office 2007 (Word. Excel and PowerPoint are essential, SharePoint designer and InfoPath are required for moderators )