Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Sunday, November 18, 2012

Binding Data from Multiple SharePoint Lists using SpSiteDataQuery




      string strList = string.Empty;
strList += "<Lists>";
       strList += "<List ID='21248773-5E96-41CE-AB58-401BC564AE1D'/>";
       strList += "<List ID='4581B2C1-4775-42FD-9FEF-66B201A3BC4A'/>";
       strList += "<List ID='6B8DE688-BD5D-4ABC-A463-9639817CF571'/>";
      strList += "</Lists>";
       sQuery.Lists = strList;
       sQuery.ViewFields = "<FieldRef Name ='Title' />";
dgvMultipleListsData.DataSource = SPContext.Current.Web.GetSiteData(sQuery);
      dgvMultipleListsData.DataBind();

Wednesday, November 07, 2012

Using SpGridView and SpMenuField within an UserControl


Using Grouping and SpMenuField in SpGridView
Ascx
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GroupByUserControl.ascx.cs" Inherits="SpDemo.GroupBy.GroupByUserControl" %>
<script type="text/javascript">
    function ShowCollapsed() {
        var rows = document.getElementsByTagName('tr');
        var numRows = rows.length;
        for (var i = 0; i < numRows; i++) {
            if (rows[i].getAttribute("isexp") != null && rows[i].getAttribute("isexp").toLowerCase() == "true") {
                if (rows[i].firstChild.firstChild != null && rows[i].firstChild.firstChild.tagName.toLowerCase() == "a") {
                    if (rows[i].firstChild.firstChild.title.toLowerCase() != "expand/collapse") {
                        rows[i].firstChild.firstChild.fireEvent("onclick");
                    }
                }
            }

        }
    }
    _spBodyOnLoadFunctionNames.push("ShowCollapsed");
</script>

<SharePoint:SPGridView ID="sgvGroupBy" runat="server" AutoGenerateColumns="false" EnableViewState="false" DataKeyNames="ID">
    <AlternatingRowStyle CssClass="ms-alternating" />
    <Columns>
    </Columns>
    <SelectedRowStyle CssClass="ms-selectednav" Font-Bold="True" />
</SharePoint:SPGridView>
<SharePoint:MenuTemplate runat="server" ID="SampleMenuTemplate">
<SharePoint:MenuItemTemplate ID="ViewMenuTemplate"  runat="server" Text="View"   />
<SharePoint:MenuItemTemplate ID="EditMenuTemplate"  runat="server" Text="Edit" ImageUrl="/_layouts/Images/edititem.gif"    />
</SharePoint:MenuTemplate>
<asp:Label ID="lblMessage" runat="server"></asp:Label>


Ascx.cs
SPMenuField sField = new SPMenuField();
                sField.HeaderText = "Task Name";
                sField.NavigateUrlFields = "ID";
                sField.NavigateUrlFormat=SPContext.Current.Web.Url + "/Lists/Tasks/DispForm.aspx?ID={0}&Source=" + Page.Request.Url;
                sField.TextFields = "Title";
                sField.MenuTemplateId = "SampleMenuTemplate";
                sField.TokenNameAndValueFields = "ItemID=ID";
                sgvGroupBy.Columns.Add(sField);
                ViewMenuTemplate.ClientOnClickNavigateUrl = SPContext.Current.Web.Url + "/Lists/Tasks/DispForm.aspx?ID=%ItemID%&Source=" + Page.Request.Url;
                EditMenuTemplate.ClientOnClickNavigateUrl = SPContext.Current.Web.Url + "/Lists/Tasks/EditForm.aspx?ID=%ItemID%&Source=" + Page.Request.Url;
                BoundField bPriorty = new BoundField();
                bPriorty.HeaderText = "Priority";
                bPriorty.DataField = "Priority";
                sgvGroupBy.Columns.Add(bPriorty);
                sgvGroupBy.AllowGrouping = true;
                sgvGroupBy.AllowGroupCollapse = true;
                sgvGroupBy.GroupFieldDisplayName = "Status";
                sgvGroupBy.GroupField = "Status";
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPWeb objWeb = SPContext.Current.Web;
                    SPList lst = objWeb.Lists["Tasks"];
                    SPQuery sQuery = new SPQuery();
                    sQuery.Query = "<OrderBy><FieldRef Name='Status' Ascending='True' /></OrderBy>";
                    sQuery.ViewFields = "<FieldRef Name='Status'  /><FieldRef Name='Title'  /><FieldRef Name='Priority'  /><FieldRef Name='EncodedAbsUrl'  />";
                    SPListItemCollection myColl = lst.GetItems(sQuery);
                    if (myColl.Count > 0)
                    {
                        sgvGroupBy.DataSource = myColl.GetDataTable();
                        sgvGroupBy.DataBind();
                    }

                });


Saturday, November 03, 2012

How to Make Second Hard Disk offline in windows server 2008 R2 64 bit

I have a two Hard Disks in my SharePoint 2010 Server.  Due to this  I am getting performance issue while working with some applications. So I want to close one hard disk. I have done some research and found the below solution given in points. Be careful while you setting your hard disk offline. Choose the right one otherwise you will get problems.


  1. Log on to your Server. 
  2. Click on Server Manager icon() next to start menu.
  3. After opening server manager go to Disk Management.
  4. Here you will find the list of Hard disks.
  5.  Right Click on Hard Disk which you don't want to use and click on Offline.