Search This Blog

Showing posts with label DownLoads. Show all posts
Showing posts with label DownLoads. Show all posts

Thursday, January 1, 2015

WCF Examples REST in SharePoint 2010

Download Code
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %> <%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %> <%@ 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" %> <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="testPage.aspx.cs" Inherits="SharePoint2010.WCF.Examples.Layouts.SharePoint2010.WCF.Examples.testPage" DynamicMasterPageFile="~masterurl/default.master" %> <asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server"> <script type="text/javascript" src="/_layouts/js/jquery.js"></script> <script type="text/javascript"> $(document).ready(function () { //use the getJSON mehtod of Jquery $.getJSON("http://ilinksys-106:8055/_vti_bin/listdata.svc/EmployeeList?$orderby=Modified%20desc", function (data) { var strTitle = ""; //prepare HTML to render output to DIV resultarea var html = ""; html = html + '<table width="100%" border="1"><tbody>'; html += '<tr><td><h3>Employee Name</h3></td><td><h3>Title</h3></td><td><h3>Employee Number</h3></td></tr>'; //iterate through all returned list items $.each(data.d.results, function (i, result) { //get item property html += '<tr><td>' + result.EmployeeName + '</td><td>' + result.Title + '</td><td>' + result.EmployeeNumber + '</td></tr>'; }); //finally close table and render HTML to DIV resultarea html = html + '</tbody></table>'; $('#resultarea').append($(html)); }); function createListItem(webUrl, listName, itemProperties, success, failure) { $.ajax({ url: webUrl + "/_vti_bin/listdata.svc/" + listName, type: "POST", processData: false, contentType: "application/json;odata=verbose", data: JSON.stringify(itemProperties), headers: { "Accept": "application/json;odata=verbose" }, success: function (data) { success(data.d); }, error: function (data) { failure(data.responseJSON.error); } }); } $("button:#Get").click(function () { var taskProperties = { 'Title': $('#txtTitle').val(), 'EmployeeName': $('#txtEmpName').val(), 'EmployeeNumber': $('#txtEmpNumber').val() }; createListItem('http://ilinksys-106:8055', 'EmployeeList', taskProperties, function (task) { alert('Item' + task.EmployeeName + ' has been created'); }, function (error) { console.log(JSON.stringify(error)); } ); }); }); </script> </asp:Content> <asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server"> <table width="500px"> <tr> <td>Employee Title</td> <td> <input id="txtTitle" type="text" /></td> </tr> <tr> <td>Employee Name</td> <td> <input id="txtEmpName" type="text" /></td> </tr> <tr> <td>Employee Number</td> <td> <input id="txtEmpNumber" type="text" /></td> </tr> <tr> <td>&nbsp;</td> <td> <button id="Get">Insert</button></td> </tr> <tr> <td colspan="2"> <div id="resultarea"></div> </td> </tr> </table> </asp:Content> <asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server"> Application Page </asp:Content> <asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server"> My Application Page </asp:Content>

Thursday, May 1, 2014

SharePoint 2010 Samples Project

SharePoint 2010 Some Samples

DownLoad SamplesSharePoint 2010

Work Flow Task- SPGridview Code

DownLoad this project Please click here Workflow Task

<%@ 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="MyTaskEventUserControl.ascx.cs" Inherits="MyWorkFLowTask.MyTaskEvent.MyTaskEventUserControl" %>
<style>
    .pagination td table
    {
        float: right;
    }
</style>
<asp:UpdatePanel ID="upMyTasks" runat="server">
    <ContentTemplate>
        <div class="panelSection actioncontainerfixed">
            <h2 class="headercolor">
                <span class="actionrequired-img"></span>My Task</h2>
            <div class="actionrequired-table">
                <asp:GridView ID="spgrdMyTasks" runat="server" CssClass="clsTable" AutoGenerateColumns="False"
                    RowStyle-CssClass="minutesrow" AlternatingRowStyle-CssClass="minutesrow" AllowPaging="true"
                    AllowSorting="true" PageSize="4" PagerSettings-Mode="NextPrevious" PagerSettings-NextPageImageUrl="../_layouts/15/Branding/images/right-nav-arrow.png"
                    PagerSettings-PreviousPageImageUrl="../_layouts/15/Branding/images/left-nav-arrow.png"
                    PagerStyle-CssClass="pagination" OnSorting="spgrdMyTasks_Sorting" OnPageIndexChanging="spgrdMyTasks_PageIndexChanging"
                    EmptyDataText="No tasks to show" OnRowDataBound="spgrdMyTasks_RowDataBound" OnRowCreated="spgrdMyTasks_RowCreated">
                    <Columns>
                        <asp:TemplateField HeaderText="Request Name" SortExpression="Title">
                            <HeaderStyle />
                            <ItemTemplate>
                                <%# checkNull(Eval("Title"))%>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Created Date" SortExpression="StartDate">
                            <HeaderStyle />
                            <ItemTemplate>
                                <%# checkDateNull(Eval("StartDate"))%>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Due Date" SortExpression="DueDate">
                            <HeaderStyle />
                            <ItemTemplate>
                                <%# checkDateNull(Eval("DueDate"))%>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Assigned To">
                            <HeaderStyle />
                            <ItemTemplate>
                                <%# checkNull(Eval("AssignedTo"))%>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Current Status" SortExpression="Status">
                            <HeaderStyle />
                            <ItemTemplate>
                                <%# checkNull(Eval("Status"))%>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </div>
            <div class="pagination_container">
                <div>
                    <asp:Label ID="lblPageCount" Visible="false" CssClass="result" runat="server"></asp:Label>
                </div>
            </div>
            <div class="clear">
            </div>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>


---------------------------------------------------------------------------
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data;
using Microsoft.SharePoint;

namespace MyWorkFLowTask.MyTaskEvent
{
    public partial class MyTaskEventUserControl : UserControl
    {
        #region Declarations
        DataTable myTasks = new DataTable();


        public class Task
        {

            public string Subject { get; set; }
            public string ActionItem { get; set; }
            public string AssignedTo { get; set; }
            public int MinuteID { get; set; }
            public int TaskID { get; set; }
            public DateTime DueDate { get; set; }
            public int Perc { get; set; }
        }

        #endregion

        /// <summary>
        /// Refresh Function
        /// </summary>
        public int Refresh
        {
            get { return 1; }
        }

        /// <summary>
        /// Custom Method to check Date null value
        /// </summary>
        /// <param name="myValue"></param>
        /// <returns></returns>
        public string checkDateNull(object myValue)
        {
            string value = Convert.ToString(myValue);

            if (string.IsNullOrEmpty(value))
            {
                return string.Empty;
            }
            else
            {
                return Convert.ToDateTime(myValue).ToString("MM/dd/yyyy");
            }
        }

        /// <summary>
        /// Custom Method to check object null value
        /// </summary>
        /// <param name="myValue"></param>
        /// <returns></returns>
        public string checkNull(object myValue)
        {
            string value = Convert.ToString(myValue);

            if (string.IsNullOrEmpty(value))
            {
                return string.Empty;
            }
            else
            {
                return myValue.ToString();
            }
        }
        /// <summary>
        /// Page Load Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            SPWeb web = SPContext.Current.Web;
            try
            {
                if (!Page.IsPostBack)
                {
                    BindMyTasks();
                }
            }
            catch (Exception exp)
            {
                //
            }
            finally
            {
                //
            }
        }

        /// <summary>
        /// Custom Method to get Tasks from SP List
        /// </summary>
        /// <returns></returns>
        DataTable GetMyTasks()
        {
            DataTable itmcoll = new DataTable();
            DataTable dt = new DataTable();

            try
            {
                SPWeb web = SPContext.Current.Web;
                SPUser user = web.CurrentUser;

                SPList task = web.Lists.TryGetList("Workflow Tasks");
                SPListItemCollection items = task.Items;
                itmcoll = items.GetDataTable();
                var query = from c in itmcoll.AsEnumerable()
                            // where Convert.ToString(c["AssignedTo"]) == SPContext.Current.Web.CurrentUser.Name
                            select c;
                dt = query.CopyToDataTable();

                if (dt != null)
                {
                    foreach (DataRow item in dt.Rows)
                    {
                        item["PercentComplete"] = Convert.ToInt32(Convert.ToDecimal(item["PercentComplete"]) * 100);
                        string Title = Convert.ToString(item["Title"]);
                        if (Title.Length > 22)
                        {
                            Title = Title.Substring(0, 22) + "...";
                            item["Title"] = Title;
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                //
            }
            finally
            {
                //
            }

            return dt;
        }

        /// <summary>
        /// Custom Method to bind tasks to the grid
        /// </summary>
        protected void BindMyTasks()
        {
            try
            {
                spgrdMyTasks.PagerTemplate = null;
                myTasks = GetMyTasks();

                if (ViewState["SortExpression"] != null && !string.IsNullOrEmpty(Convert.ToString(ViewState["SortExpression"])))
                {
                    myTasks = SortTable(myTasks);
                }

                spgrdMyTasks.DataSource = myTasks;
                spgrdMyTasks.DataBind();

                if (myTasks != null && myTasks.Rows.Count > 0)
                {
                    lblPageCount.Text = Convert.ToString(myTasks.Rows.Count) + " Records";
                }
                else
                {
                    lblPageCount.Text = "No Records Found";
                }
            }
            catch (Exception exp)
            {
                //
            }
            finally
            {
                //
            }
        }

        /// <summary>
        /// Custom method to sort Grid Data
        /// </summary>
        /// <param name="dtGridData"></param>
        /// <returns></returns>
        DataTable SortTable(DataTable dtGridData)
        {
            try
            {
                DataView dvGridDataView = dtGridData.DefaultView;
                string strSortOrder = string.Empty;

                if (gridViewSortDirection == SortDirection.Ascending)
                {
                    strSortOrder = "asc";
                }
                else
                {
                    gridViewSortDirection = SortDirection.Ascending;
                    strSortOrder = "desc";
                }

                dvGridDataView.Sort = ViewState["SortExpression"] + " " + strSortOrder;
                dtGridData = dvGridDataView.ToTable();

            }
            catch (Exception exp)
            {
                //
            }
            finally
            {
                //
            }

            return dtGridData;
        }

        /// <summary>
        /// Page Index Changing Event for the Grid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void spgrdMyTasks_PageIndexChanging(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)
        {
            try
            {
                spgrdMyTasks.PageIndex = e.NewPageIndex;
                BindMyTasks();
            }
            catch (Exception exp)
            {
                //
            }
            finally
            {
                // 
            }
        }

        /// <summary>
        /// Row Created Event for the Grid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void spgrdMyTasks_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
        {
            try
            {
                if (e.Row.RowType == DataControlRowType.Header)
                {
                    int sortColumnIndex = getSortColumnIndex();

                    if (sortColumnIndex != -1)
                    {
                        addSortImage(sortColumnIndex, e.Row);
                    }
                }
            }
            catch (Exception exp)
            {
                //
            }
            finally
            {
                //
            }
        }

        /// <summary>
        /// Grid Data Sorting Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void spgrdMyTasks_Sorting(object sender, System.Web.UI.WebControls.GridViewSortEventArgs e)
        {
            try
            {
                DataTable dtGridData = GetMyTasks();
                ViewState["SortExpression"] = e.SortExpression;
                DataView dvGridDataView = dtGridData.DefaultView;
                string strSortOrder = "";

                if (gridViewSortDirection == SortDirection.Ascending)
                {
                    gridViewSortDirection = SortDirection.Descending;
                    strSortOrder = "desc";
                }
                else
                {
                    gridViewSortDirection = SortDirection.Ascending;
                    strSortOrder = "asc";
                }

                dvGridDataView.Sort = ViewState["SortExpression"] + " " + strSortOrder;
                dtGridData = dvGridDataView.ToTable();
                spgrdMyTasks.DataSource = dtGridData;
                spgrdMyTasks.DataBind();
            }
            catch (Exception exp)
            {
                //
            }
            finally
            {
                //
            }
        }

        /// <summary>
        /// Gets the Column Index of the Columns based on which the Sorting should be done.
        /// </summary>
        /// <returns></returns>
        private int getSortColumnIndex()
        {
            try
            {
                foreach (DataControlField field in spgrdMyTasks.Columns)
                {
                    if (field.SortExpression == (string)ViewState["SortExpression"])
                    {
                        return spgrdMyTasks.Columns.IndexOf(field);
                    }
                }
            }
            catch (Exception exp)
            {
                //
            }
            finally
            {
                //
            }

            return -1;
        }

        /// <summary>
        /// This method swaps the sort direction of the Grid based upon the current sorted direction.
        /// If the current sorted order is Ascending then the new sort direction will be Descending
        /// or Vice versa.
        /// </summary>
        private SortDirection gridViewSortDirection
        {
            get
            {
                if (ViewState["SortOrder"] == null)
                {
                    ViewState["SortOrder"] = SortDirection.Ascending;
                }
                return (SortDirection)ViewState["SortOrder"];
            }
            set
            {
                ViewState["SortOrder"] = value;
            }
        }

        /// <summary>
        /// Adds Sort Image to Sorted Column.
        /// </summary>
        /// <param name="columnIndex"></param>
        /// <param name="headerRow"></param>
        private void addSortImage(int columnIndex, GridViewRow headerRow)
        {
            try
            {
                // Create the sorting image based on the sort direction.
                Image sortImage = new Image();
                if (gridViewSortDirection == SortDirection.Ascending)
                {
                    sortImage.ImageUrl = "~/_layouts/15/Branding/images/up_arrow.png";
                    sortImage.AlternateText = "Ascending Order";
                }
                else
                {
                    sortImage.ImageUrl = "~/_layouts/15/Branding/images/Down_arrow.png";
                    sortImage.AlternateText = "Descending Order";
                }
                // Add the image to the appropriate header cell.
                headerRow.Cells[columnIndex].Controls.Add(sortImage);
            }
            catch (Exception exp)
            {
                //
            }
            finally
            {
                // 
            }
        }

        protected void spgrdMyTasks_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Pager)
            {
                int count = e.Row.Cells[0].Controls[0].Controls[0].Controls.Count;

                if (count == 1)
                {
                    if (spgrdMyTasks.PageIndex == 0)
                    {
                        TableCell next = (TableCell)e.Row.Cells[0].Controls[0].Controls[0].Controls[0];
                        next.ToolTip = "Next";
                    }
                    else
                    {
                        TableCell prev = (TableCell)e.Row.Cells[0].Controls[0].Controls[0].Controls[0];
                        prev.ToolTip = "Previous";
                    }
                }
                else if (count == 2)
                {
                    TableCell prev = (TableCell)e.Row.Cells[0].Controls[0].Controls[0].Controls[0];
                    prev.ToolTip = "Previous";
                    TableCell next = (TableCell)e.Row.Cells[0].Controls[0].Controls[0].Controls[1];
                    next.ToolTip = "Next";
                }
            }
        }
    }
}