Friday, 7 June 2013

Displaying the user details(dropdown selection) in InfoPath based on dropdown selection without code:



2.After selecting the Username from dropdown its Automatically  displaying the corresponding user details(Originating GroupName,Designation,Account…etc .As shown belw)

Connect to the user information list and bind the values to the dropdown . by default  it takes user id id and name value from the user information list.create some dropdowns and select the user corresponding values(depart ment…) and make it as a hidden fields  then only the values save into dropdown see the below screen shot..


 And set the field values to the originating name(dropdown)



Originating groupname set field value: see the below screen shot for displaying the originating group value

Here field=originating name(disply originating name field)
Value(see the below screen shot)=department is from userinformation list(see the below screen shot) and that value id is equal to originating name(field 4)
 





Same to remaing fields…

Displaying the user details in InfoPath based on user with code:

Displaying the user details in InfoPath based on user with code:
1.design form
2) Form options àsecurity and trustàFull trust
3) Select language to c#.right click on button click on edit form code

Code

SPSite site = new SPSite("http://syncgdc1412:3333/sites/Testingsite");
            SPWeb web = site.OpenWeb();
            SPList list = web.Lists["User Information List"];
            XPathNavigator xpnav = this.CreateNavigator().SelectSingleNode("/my:myFields", this.NamespaceManager);
            XPathNavigator xpnav1 = xpnav.SelectSingleNode("/my:myFields/my:username", this.NamespaceManager);
            string s = xpnav1.ToString();
            SPListItemCollection itemcol;
            SPQuery qry = new SPQuery();
            qry.Query = "<Where><Or><Eq><FieldRef Name='Title' /><Value Type='Text'>" + s.ToString() + "</Value></Eq><Eq><FieldRef Name='UserName' /><Value Type='Text'>" + s.ToString() + "</Value></Eq></Or></Where>";
                //"<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + s.ToString() + "</Value></Eq></Where>";
            itemcol = list.GetItems(qry);
            foreach (SPListItem item in itemcol)
            {
                xpnav.SelectSingleNode("/my:myFields/my:field2", this.NamespaceManager).SetValue(item["EMail"].ToString());
                //xpnav.SelectSingleNode("/my:myFields/my:Phone", this.NamespaceManager).SetValue(item["MobilePhone"].ToString());
                xpnav.SelectSingleNode("/my:myFields/my:SipAddress", this.NamespaceManager).SetValue(item["SipAddress"].ToString());
                xpnav.SelectSingleNode("/my:myFields/my:Department", this.NamespaceManager).SetValue(item["Department"].ToString());
                xpnav.SelectSingleNode("/my:myFields/my:JobTitle", this.NamespaceManager).SetValue(item["JobTitle"].ToString());


4)view certificateàany errorsàcopy or create certificateàsave the certificate in desktopàgoto runàmmcàright click on Console1àAll tasksàImport(IMPORT THE CERTIFICATE)àAFTER THAT GO AND CHECK IF THERE IS ANY ERRORS IN THE FORM.

5)Publish to form library.            }

Displaying the user details in InfoPath based on user without code and getting the current login user details

Displaying the user details in InfoPath based on user without code:
1)      Design form

2)      Go to data connectionsàReceive dataàsite urlàSharePoint library or listàUser information      listàHere select the required columns

3)  Create one hidden field (text box) name it hidden
4) Give some rules.
    Set field value (username to hidden field)
Another rule:User name(Means title(field name in this form))
Title is blank. Give a some screen tip
 
5) Add one button name it display.select button go to  control propertiesàselect Refresh

6) Add a rules to hidden field (set field values to Hidden field)
In the set afield value value section go and select the field name (for ex Email).after that  select standard viewàin the field section select user information listàselect Work email from user information listàFilter dataàEntered user name (Title field in our form ) is equal to USER NAME IN THE USER INFORMATION LIST..

step by step explanation for one field:
1)

2)select email


3)Select standard view after that select user information list from the fields section


4) select data fieldsàselect work emailà

5)select filter dataàaddàselect the user name in user information list is equal to Title(form field entered user name)
Selecting the form field like this
from MainàData fields section

After selecting the main select the form field user name(Title in our form)


Getting the current login  user details
Add the function username() to text box based on that filter the details from user information list

                                                Same steps like above

Wednesday, 5 June 2013

Grid binding code


 <asp:GridView ID="gvRInProgress" runat="server" Width="850px" CellPadding="4" EnableModelValidation="True"
                            ForeColor="#333333" GridLines="None" AutoGenerateColumns="false" OnRowCommand="gvRInProgress_RowCommand"
                            EmptyDataText="In Progress Data not found." AllowPaging="True" OnPageIndexChanging="gvRInProgress_PageIndexChanging">
                            <AlternatingRowStyle BackColor="White" HorizontalAlign="Left" />
                            <Columns>
                                <asp:TemplateField HeaderText="Source">
                                    <ItemTemplate>
                                        <asp:Label ID="lblListName" runat="server" Width="100px" Text='<%# DataBinder.Eval(Container.DataItem, "List") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Job Description">
                                    <ItemTemplate>
                                        <asp:Label ID="lblId" Visible="false" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ID") %>'></asp:Label>
                                        <asp:LinkButton ID="lnkbtnViewItem" runat="server" Width="150px" Text='<%# DataBinder.Eval(Container.DataItem, "Title") %>'
                                            CommandName="ViewItem"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Comments History">
                                    <ItemTemplate>
                                        <asp:Label ID="lblCommentsHistory" Width="250px" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Comments") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Comments">
                                    <ItemTemplate>
                                        <asp:TextBox ID="txtComments" runat="server" Width="100px"></asp:TextBox>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Action">
                                    <ItemTemplate>
                                        <asp:Button ID="btnSendbacktocustomer" runat="server" CommandName="SendBack" Width="100px"
                                            Text="SendBack" />
                                        <asp:Button ID="btnSaveComments" runat="server" CommandName="SaveComments" Width="100px"
                                            Text="Save" />
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                            <EditRowStyle BackColor="#7C6F57" HorizontalAlign="Left" />
                            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
                            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
                            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                            <RowStyle BackColor="#E3EAEB" HorizontalAlign="Left" />
                            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" HorizontalAlign="Left" />
                        </asp:GridView>


  private void BindData(String strStatus)
        {
            DataTable dtGlobal = new DataTable();
            DataRow drGlobal;

            //Data table column declaration
            dtGlobal.Columns.Add("List");
            dtGlobal.Columns.Add("Id");
            dtGlobal.Columns.Add("Title");
            dtGlobal.Columns.Add("Comments");
            using (SPSite oCurrentSite = new SPSite(SPContext.Current.Web.Url))
            {
                using (SPWeb oCurrentWeb = oCurrentSite.OpenWeb())
                {

                    SPList oListResource = null;
                    SPList oListTools = null;
                    SPList oListSolution = null;
                    SPList oListExecution = null;

                    oListResource = oCurrentWeb.Lists["Service Request"];
                    oListTools = oCurrentWeb.Lists["Request for Tools"];
                    oListSolution = oCurrentWeb.Lists["Request for Solution"];
                    oListExecution = oCurrentWeb.Lists["Request for Execution"];


                    String queryResource = "";
                    String queryTools = "";
                    String querySolution = "";
                    String queryExecution = "";
                    if (strStatus == "Inprogress")
                    {
                        queryResource = @"<Where><And><Eq><FieldRef Name='Status' /><Value Type='Text'>" + strStatus + "</Value></Eq><Eq><FieldRef Name='Business_x0020_Unit'/><Value Type='Text'>" + ViewState["GroupName"] + "</Value></Eq></And></Where>";
                        queryTools = @"<Where><And><Eq><FieldRef Name='Status' /><Value Type='Text'>" + strStatus + "</Value></Eq><Eq><FieldRef Name='Business_x0020_Unit'/><Value Type='Text'>" + ViewState["GroupName"] + "</Value></Eq></And></Where>";
                        querySolution = @"<Where><And><Eq><FieldRef Name='Status' /><Value Type='Text'>" + strStatus + "</Value></Eq><Eq><FieldRef Name='Business_x0020_Unit'/><Value Type='Text'>" + ViewState["GroupName"] + "</Value></Eq></And></Where>";
                        queryExecution = @"<Where><And><Eq><FieldRef Name='Status' /><Value Type='Text'>" + strStatus + "</Value></Eq><Eq><FieldRef Name='Business_x0020_Unit'/><Value Type='Text'>" + ViewState["GroupName"] + "</Value></Eq></And></Where>";
                    }
                    else if (strStatus == "Pending")
                    {
                        queryResource = @"<Where><And><Eq><FieldRef Name='Status' /><Value Type='Text'>" + strStatus + "</Value></Eq><Eq><FieldRef Name='Author'/><Value Type='Text'>" + SPContext.Current.Web.CurrentUser.Name.ToString() + "</Value></Eq></And></Where>";
                        queryTools = @"<Where><And><Eq><FieldRef Name='Status' /><Value Type='Text'>" + strStatus + "</Value></Eq><Eq><FieldRef Name='Author'/><Value Type='Text'>" + SPContext.Current.Web.CurrentUser.Name.ToString() + "</Value></Eq></And></Where>";
                        querySolution = @"<Where><And><Eq><FieldRef Name='Status' /><Value Type='Text'>" + strStatus + "</Value></Eq><Eq><FieldRef Name='Author'/><Value Type='Text'>" + SPContext.Current.Web.CurrentUser.Name.ToString() + "</Value></Eq></And></Where>";
                        queryExecution = @"<Where><And><Eq><FieldRef Name='Status' /><Value Type='Text'>" + strStatus + "</Value></Eq><Eq><FieldRef Name='Author'/><Value Type='Text'>" + SPContext.Current.Web.CurrentUser.Name.ToString() + "</Value></Eq></And></Where>";
                    }
                    else if (strStatus == "Completed")
                    {
                        queryResource = @"<Where><And><Eq><FieldRef Name='Status' /><Value Type='Text'>" + strStatus + "</Value></Eq><Eq><FieldRef Name='Author'/><Value Type='Text'>" + SPContext.Current.Web.CurrentUser.Name.ToString() + "</Value></Eq></And></Where>";
                        queryTools = @"<Where><And><Eq><FieldRef Name='Status' /><Value Type='Text'>" + strStatus + "</Value></Eq><Eq><FieldRef Name='Author'/><Value Type='Text'>" + SPContext.Current.Web.CurrentUser.Name.ToString() + "</Value></Eq></And></Where>";
                        querySolution = @"<Where><And><Eq><FieldRef Name='Status' /><Value Type='Text'>" + strStatus + "</Value></Eq><Eq><FieldRef Name='Author'/><Value Type='Text'>" + SPContext.Current.Web.CurrentUser.Name.ToString() + "</Value></Eq></And></Where>";
                        queryExecution = @"<Where><And><Eq><FieldRef Name='Status' /><Value Type='Text'>" + strStatus + "</Value></Eq><Eq><FieldRef Name='Author'/><Value Type='Text'>" + SPContext.Current.Web.CurrentUser.Name.ToString() + "</Value></Eq></And></Where>";
                    }

                    queryResource = String.Format(queryResource, "Status");
                    queryTools = String.Format(queryTools, "Status");
                    querySolution = String.Format(querySolution, "Status");
                    queryExecution = String.Format(queryExecution, "Status");

                    SPQuery spQueryResource = new SPQuery();
                    SPQuery spQueryTools = new SPQuery();
                    SPQuery spQuerySolution = new SPQuery();
                    SPQuery spQueryExecution = new SPQuery();

                    spQueryResource.Query = queryResource;
                    spQueryTools.Query = queryTools;
                    spQuerySolution.Query = querySolution;
                    spQueryExecution.Query = queryExecution;

                    SPListItemCollection itemsResource = oListResource.GetItems(spQueryResource);
                    SPListItemCollection itemsTools = oListTools.GetItems(spQueryTools);
                    SPListItemCollection itemsSolution = oListSolution.GetItems(spQuerySolution);
                    SPListItemCollection itemsExecution = oListExecution.GetItems(spQueryExecution);

                    DataTable dtResource = new DataTable();
                    DataTable dtTools = new DataTable();
                    DataTable dtSolution = new DataTable();
                    DataTable dtExecution = new DataTable();

                    dtResource = itemsResource.GetDataTable();
                    dtTools = itemsTools.GetDataTable();
                    dtSolution = itemsSolution.GetDataTable();
                    dtExecution = itemsExecution.GetDataTable();

                    

     gvRInProgress.DataSource = dtResource;
                    gvRInProgress.DataBind();

Remove/Hide the Tabs(contextual tab group on Ribbon)

I want to Remove/Hide Tabs [Page Tab , Edit Tab, etc.]  and Contextual tab groups [List Tools Tab, Editing Tools Tab, etc.]  as marked in Red below using SharePoint Designer 2010.


Using CSS we can do it, Please copy the following code in your SharePoint site master page.

<style type="text/css">
      .ms-cui-tabBody, .ms-cui-tt-s{
            display:none !IMPORTANT;
      }
      .ms-cui-tt, .ms-cui-cg, .ms-cui-cg-lb{
            display:none !IMPORTANT;
      }
      .s4-ribbonrowhidetitle, #s4-ribbonrow{
      height:40px !IMPORTANT;
      }
      #s4-titlerow{
            display:block !IMPORTANT;    
      }
      </style>

I hope it will help you.

 

 





Summing the Calculated Columns

Reference url

http://blog.metrostarsystems.com/2012/12/03/jennys-sharepoint-tip-sum-calculated-columns/

About Summing Calculated Columns
Calculated columns are great, but if you expect to be able to total calculated columns using the Totals feature in the View Settings, think again.  To sum calculated columns in a list you need SharePoint Designer 2010, a web part page, a data source, and a line of code.

Example Overview

This example will total the results of a calculated field in a custom list. The list will be inserted as a data source on a web part page.  The list and web part page have been previously created and the creation of these items is not documented in the demo.

On a web part page called Demo Calculated Columns.aspx, an empty data source will be added with four columns inserted from the calculatedcolums list as the data source:  Title, column1, columns2, and 1and2.

Creating a Totals Field for a Calculated Column

 1.       Create the list
This demo does not include screenshots or instructions for building the list used in this example.  To recreate this demo, create a new custom list and add the three columns outlined in the Example Overview section.
2.       Create a web part page
This demo does not include screenshots or instructions for creating the web part page used in this example.  To recreate this demo, create a web part page somewhere in your test site. 
3.       Add an empty data source and configure
4.       Add XSL Value of Select data

Add an Empty Data Source and Configure

 1.    Open the Demo Calculated Columns.aspx page in Advanced Mode in SharePoint Designer in Split mode.  In the design portion, click and place your cursor in the PlaceHolderMain section of the page.  From the Ribbon, on the Insert tab, select Data View, Empty Data View

2.       Select Click here to select a data source and choose calculatedcolumns.  The Data Source details pane will open on the right.  Insert the following fields into the new data source:  Title, column1, column2,and 1and2.

3.  The totals information should be included in a new row at the bottom of the list.  To insert a new row, in the last cell of the table, right-click and select Insert, Row Below.

4.        Your cursor will now be in the last cell on the bottom row of the table in the design pane.  In the code pane, the cursor will be placed in its current cell position. 

 Add “XSL Value of Select” Data

1.     Continuing from step 4 above, we want to delete the current code of the new cell.  For the active cell, copy the code snippet <td><xsl:text xmlns:ddwrt=”http://schemas.microsoft.com/WebParts/v2/DataView/runtime” ddwrt:nbsp-preserve=”yes” disable-output-escaping=”yes”>&amp;nbsp;</xsl:text> and delete it. 

2.       Input the following code (replace the highlighted text with your column name) and Save your page: 
Note – Designer is precise when it comes to code.  If you copy and paste the row of code below, after pasting into Designer, delete the in the code pane, then re-add them.   Otherwise, due to font differences, a XSLT style sheet error will display.
<td ><xsl:value-of select=sum(/dsQueryResponse/Rows/Row/@_x0031_and2) /></td>

3.       The calculated column is now totaled. 
 

Additional Modifications

Add the Toolbar

So that users can interact with the data source by adding new items, setting alerts, and filtering and sorting on column headers, add the SharePoint Toolbar. 
1.     To add the Toolbar, from the Ribbon, on the Design tab, in the Toolbar section, click Options, then select SharePoint ToolbarSave the page in Designer.  Note:  Alternatively to only enable sorting and filtering on column headers, leave the Toolbar setting as is and in the Show/Hide section check Sort & Filter on Headers.

2.       The data source now displays with the Toolbar.

Add the Quick Launch to the page

So that users can navigate easily around the site, add the left hand naviation, the Quick Launch, to the web part page.
1.  Delete the following lines of code:
<asp:Content ContentPlaceHolderId=”PlaceHolderNavSpacer” runat=”server”></asp:Content>
<asp:Content ContentPlaceHolderId=”PlaceHolderLeftNavBar” runat=”server”></asp:Content>
<style type=”text/css”>body #s4-leftpanel { display:none;}.s4-ca { margin-left:0px;}</style>


 2.       The Demo Calculated Columns page now displays with the Quick Launch.