Wednesday, 13 May 2015

hotfix for problem with SharePoint PeopleEditor in IE-9


Sharepoint 2010 and IE9 compatibility


I created a javascript file called entityeditor.ie9fix.js, added the javascript code that will follow, and saved it in /layouts/1033.


https://social.msdn.microsoft.com/Forums/en-US/90b3835c-6754-4bb6-9fd4-b74f16f236ff/sharepoint-2010-and-ie9-compatibility?forum=sharepointgeneralprevious


In my master page I added
<script type="text/javascript" src="/_layouts/1033/entityeditor.ie9fix.js"></script>
to the very BOTTOM of the master page, right before the following tags:
<input type="text" name="__spDummyText1" style="display:none;" size="1"/>
<input type="text" name="__spDummyText2" style="display:none;" size="1"/>

function ConvertEntityToSpan(ctx, entity)
{ULSGjk:;
    if(matches[ctx]==null)
        matches[ctx]=new Array();
    var key=entity.getAttribute("Key");
    var displayText=entity.getAttribute("DisplayText");
    var isResolved=entity.getAttribute("IsResolved");
    var description=entity.getAttribute("Description");
    var style='ms-entity-unresolved';
    if(isResolved=='True')
        style='ms-entity-resolved';
    var spandata="<span id='span"+STSHtmlEncode(key)+"' isContentType='true' tabindex='-1' class='"+style+"' ";
    if (browseris.ie8standard)
        spandata+="onmouseover='this.contentEditable=false;' onmouseout='this.contentEditable=true;' contentEditable='true' ";
    else
        spandata+="contentEditable='false' ";
    spandata+="title='"+STSHtmlEncode(description)+"'>"
    spandata+="<div style='display:none;' id='divEntityData' ";
    spandata+="key='"+STSHtmlEncode(key)+"' displaytext='"+STSHtmlEncode(displayText)+"' isresolved='"+STSHtmlEncode(isResolved)+"' ";
    spandata+="description='"+STSHtmlEncode(description)+"'>";
    var multipleMatches=EntityEditor_SelectSingleNode(entity, "MultipleMatches");
    matches[ctx][key]=multipleMatches;
    var extraData=EntityEditor_SelectSingleNode(entity, "ExtraData");
    if(extraData)
    {
        var data;
        if(extraData.firstChild)
            data=extraData.firstChild.xml;
        if(!data) data=extraData.innerXml || extraData.innerHTML;
        if(!data && document.implementation && document.implementation.createDocument)
        {
            var serializer=new XMLSerializer();
            data=serializer.serializeToString(extraData.firstChild);

                    // **** CUSTOM FUNCTION ****
            data = fixDataInIE9(data);
        }
        if(!data) data='';
        spandata+="<div data='"+STSHtmlEncode(data)+"'></div>";
    }
    else
    {
        spandata+="<div data=''></div>";
    }
    spandata+="</div>";
    if(PreferContentEditableDiv(ctx))
    {
        if(browseris.safari)
        {
            spandata+="<span id='content' tabindex='-1' contenteditable='false'  onmousedown='onMouseDownRw(event);' onContextMenu='onContextMenuSpnRw(event,ctx);' >";
        }
        else
        {
            spandata+="<span id='content' tabindex='-1' contenteditable onmousedown='onMouseDownRw(event);' onContextMenu='onContextMenuSpnRw(event,ctx);' >";
        }
    }
    else
    {
        spandata+="<span id='content' tabindex='-1' contenteditable onmousedown='onMouseDownRw(event);' onContextMenu='onContextMenuSpnRw(event,ctx);' >";
    }
    if (browseris.ie8standard)
        spandata+="\r";
    if(displayText !='')
        spandata+=STSHtmlEncode(displayText);
    else
        spandata+=STSHtmlEncode(key);
    if (browseris.ie8standard)
        spandata+="\r</span></span>\r";
    else
        spandata+="</span></span>";
    return spandata;
}

// **** CUSTOM FUNCTION ****
function fixDataInIE9(data)
{
    if(data.indexOf('<ArrayOfDictionaryEntry>') >= 0)
    {
        data = data.replace('<ArrayOfDictionaryEntry>', '<ArrayOfDictionaryEntry xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema-instance\">');
    }
    return data;
}


After setting that up and publishing the master page I reloaded my site and had no problems saving people from the people picker. Heck of a lot easier than trying to get everyone to use firefox, or some kind of plugin.
PS: I marked my code with // ** CUSTOM FUNCTION **
/**** UPDATED 4/25/2012 ******/
Added reference to the exact location in which to place updated entityeditor.ie9fix.js script tag. Placing the script here will allow you to create new items and edit existing ones which contain a people picker control.


Tuesday, 12 May 2015

Create Run time GridView control in SharePoint 2007/2010

https://msdn.microsoft.com/es-es/library/office/hh857549(v=office.14).aspx

Code paste on Web Part in SharePoint 2007/2010

  //varible declaration
       // private string strResult;
        protected TextBox txtSearch;
        protected Button btnSearch;
        protected Label lblErrMsg;
        protected GridView GridSearch;
        string CurrentURL = SPContext.Current.Web.Url;

        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            try
            {
               // strResult += "CreateChildControls<br>";       //creating error label controls
                this.lblErrMsg = new Label();
                this.lblErrMsg.ID = "lblErrMsg";
                this.lblErrMsg.Text = string.Empty;
                this.Controls.Add(lblErrMsg);                //creating text controls
                this.txtSearch = new TextBox();
                this.txtSearch.ID = "txtSearch";
                this.txtSearch.Text = string.Empty;
                this.Controls.Add(txtSearch);                //creating button controls
                this.btnSearch = new Button();
                this.btnSearch.ID = "btnSearch";
                this.btnSearch.Text = "Search";
                this.btnSearch.Click += new EventHandler(btnSearch_Click);
                this.Controls.Add(btnSearch);


                //gridview Initialization

                this.GridSearch = new GridView();
                this.GridSearch.Width = Unit.Percentage(100);
                this.GridSearch.AlternatingRowStyle.BackColor = System.Drawing.Color.LightGray;
                this.GridSearch.EmptyDataText = "No records found.";
                this.GridSearch.ID = "GridSearch";
                this.GridSearch.Width = Unit.Percentage(100);
                this.GridSearch.CellPadding = 0;
                this.GridSearch.CellSpacing = 0;
                //this.GridSearch.BorderWidth = 1;
                this.GridSearch.HeaderStyle.Font.Bold = true;
                this.GridSearch.BorderWidth = Unit.Pixel(1);
                this.GridSearch.AllowPaging = true;
                this.GridSearch.PageSize = 2;
               
                this.GridSearch.AutoGenerateColumns = false;

                BoundField id = new BoundField();              
                id.DataField = "ID";
                id.HeaderText = "ID";
                id.Visible = false;
                this.GridSearch.Columns.Add(id);
               
                //HyperLinkField title1 = new HyperLinkField();
                //title1.DataTextField = "Title";
                //title1.HeaderText = "Title";
                //title1.NavigateUrl = "/Lists/PU/DispForm.aspx?ID=" + ID;
                //title1.Target = "_blank";
                //this.GridSearch.Columns.Add(title1);


                BoundField title = new BoundField();
                title.DataField = "Title";
                title.HeaderText = "Title";              
                this.GridSearch.Columns.Add(title);

                //TemplateField tfield = new TemplateField();
                //tfield.HeaderText = "View";
                //this.GridSearch.Columns.Add(tfield);

                BoundField BU = new BoundField();
                BU.DataField = "BU";
                BU.HeaderText = "BU";
                this.GridSearch.Columns.Add(BU);

                BoundField technology = new BoundField();
                technology.DataField = "Technology";
                technology.HeaderText = "Technology";
                this.GridSearch.Columns.Add(technology);

                //BoundField startDate = new BoundField();
                //startDate.DataField = "StartDate";
                //startDate.HeaderText = "Start Date";
                //startDate.DataFormatString = "{0:MMMM d, yyyy}";
                //this.GridSearch.Columns.Add(startDate);

                this.GridSearch.PageIndexChanging += new GridViewPageEventHandler(GridSearch_PageIndexChanging);
                this.GridSearch.RowDataBound += new GridViewRowEventHandler(GridSearch_RowDataBound);
               // this.GridSearch.RowDataBound += new GridViewPageEventHandler(GridSearch_RowDataBound);
                this.Controls.Add(this.GridSearch);


            }
            catch (Exception ex)
            {
                this.lblErrMsg.Text = ex.Message.ToString();
            }
        }

        void GridSearch_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    Label lblID = new Label();
                    lblID.ID = "lblID";
                    lblID.Text = (e.Row.DataItem as DataRowView).Row["ID"].ToString();
                    e.Row.Cells[0].Controls.Add(lblID);

                    HyperLink hplTitle = new HyperLink();
                    hplTitle.ID = "hplTitle";
                    hplTitle.Text = (e.Row.DataItem as DataRowView).Row["Title"].ToString();
                    hplTitle.NavigateUrl = "/Lists/PU/DispForm.aspx?ID=" + lblID.Text.Trim();
                    hplTitle.Target = "_blank";
                    e.Row.Cells[1].Controls.Add(hplTitle);

                    Label lblBU = new Label();
                    lblBU.ID = "lblBU";
                    lblBU.Text = (e.Row.DataItem as DataRowView).Row["BU"].ToString();
                    e.Row.Cells[2].Controls.Add(lblBU);

                    Label lblTechnology = new Label();
                    lblTechnology.ID = "lblTechnology";
                    lblTechnology.Text = (e.Row.DataItem as DataRowView).Row["Technology"].ToString();
                    e.Row.Cells[3].Controls.Add(lblTechnology);
                }            
            }
            catch (Exception ex)
            {
                this.lblErrMsg.Text = ex.Message.ToString();
            }
        }

        //protected void GridSearch_RowDataBound(object sender, GridViewRowEventArgs e)
        //{
        //    //Label lblID;
        //    //HyperLink hplTitle;
        //    //Label lblBU;
        //    //Label lblTechnology;
        //    //HyperLinkField hplTitle;
        //    try
        //    {
        //        //if (e.Row.RowType == DataControlRowType.DataRow)
        //        //{
        //        //    TextBox txtCountry = new TextBox();
        //        //    txtCountry.ID = "txtCountry";
        //        //    txtCountry.Text = (e.Row.DataItem as DataRowView).Row["Country"].ToString();
        //        //    e.Row.Cells[1].Controls.Add(txtCountry);

        //        //    LinkButton lnkView = new LinkButton();
        //        //    lnkView.ID = "lnkView";
        //        //    lnkView.Text = "View";
        //        //    lnkView.Click += ViewDetails;
        //        //    lnkView.CommandArgument = (e.Row.DataItem as DataRowView).Row["Id"].ToString();
        //        //    e.Row.Cells[2].Controls.Add(lnkView);
        //        //}


        //        //if (e.Row.RowType == DataControlRowType.DataRow)
        //        //{
        //        //    Label lblID = (Label)e.Row.FindControl("lblID");
        //        //    HyperLink hplTitle = (HyperLink)e.Row.FindControl("hplTitle");
        //        //    hplTitle.NavigateUrl = "/Lists/PU/DispForm.aspx?ID=" + lblID.Text.Trim();
        //        //    Label lblBU = (Label)e.Row.FindControl("lblBU");
        //        //    Label lblTechnology = (Label)e.Row.FindControl("lblTechnology");
        //        //}
        //    }
        //    catch (Exception ex)
        //    {
        //        this.lblErrMsg.Text = ex.Message.ToString();
        //    }
        //}

        protected void GridSearch_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            try
            {
                if (ViewState["SearchPageIndexChanging"] != null)
                {
                    GridSearch.PageIndex = e.NewPageIndex;
                    GridSearch.DataSource = ViewState["SearchPageIndexChanging"];
                    GridSearch.DataBind();
                    GridSearch.Visible = true;
                }
            }
            catch (Exception ex)
            {
                this.lblErrMsg.Text = ex.Message.ToString();
            }
        }

         public override void RenderControl(HtmlTextWriter writer)
        {
            try
            {
                //this method ensure all created child controls
                base.CreateChildControls();
                //this.strResult += "RenderControl<br>";
                //table start
                writer.Write("<table id='tblTest' width='770px' border='0' cellpadding='0' cellspacing='0'>");              
                writer.Write("<tr>");
                writer.Write("<td align='left' style='padding-left:10px;'>");
                this.txtSearch.RenderControl(writer);
                writer.Write("</td>");
                writer.Write("<td>");
                this.btnSearch.RenderControl(writer);
                writer.Write("</td>");
                writer.Write("</tr>");

                writer.Write("<tr>");
                writer.Write("<td colspan='2' align='left' >");
                this.lblErrMsg.RenderControl(writer);
                writer.Write("</td>");
                writer.Write("</tr>");


                writer.Write("<tr>");
                writer.Write("<td colspan='2' align='left' style='padding-left:10px;' >");
                this.GridSearch.RenderControl(writer);
                writer.Write("</td>");
                writer.Write("</tr>");

                writer.Write("</table>");
                //table end
            }
            catch (Exception ex)
            {
                this.lblErrMsg.Text = ex.Message.ToString();
            }
        }

        void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                getDatabind(txtSearch.Text.Trim());
            }
            catch (Exception ex)
            {
                lblErrMsg.Text = ex.Message;
            }
        }

        public void getDatabind(string search)
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite site = new SPSite(CurrentURL))
                    {
                        using (SPWeb web = site.OpenWeb())
                        {
                            //DataTable dt = new DataTable();
                            //dt.Clear();
                            //dt.Columns.Add("ID");
                            //dt.Columns.Add("Title");
                            //dt.Columns.Add("BU");
                            //dt.Columns.Add("Technology");

                            SPList list = web.Lists["PU"];
                            SPQuery query = new SPQuery();
                            ViewState["SearchPageIndexChanging"] = null;
                            query.Query = "<Where><Or><Contains><FieldRef Name='Title' /><Value Type='Text'>" + search + "</Value></Contains><Or><Contains><FieldRef Name='BU' /><Value Type='Text'>" + search + "</Value></Contains><Contains><FieldRef Name='Technology' /><Value Type='Text'>" + search + "</Value></Contains></Or></Or></Where>";
                            query.ViewFields = @"<FieldRef Name='ID' /><FieldRef Name='Title' /><FieldRef Name='BU' /><FieldRef Name='Technology' />";
                            query.ViewFieldsOnly = true;
                            //SPListItemCollection items = list.GetItems(query);
                            //if (list != null && list.Items.Count > 0)
                            //{
                            //    foreach (SPListItem item in items)
                            //    {
                            //        DataRow dr = dt.NewRow();
                            //        dr["ID"] = this.GetFieldValue(item, "ID");
                            //        dr["Title"] = this.GetFieldValue(item, "Title"); //string.Concat(list.DefaultDisplayFormUrl, string.Format("?ID={0}", item.ID));
                            //        dr["BU"] = this.GetFieldValue(item, "BU");
                            //        dr["Technology"] = this.GetFieldValue(item, "Technology");
                            //        dt.Rows.Add(dr);
                            //    }
                            //    if (dt != null && dt.Rows.Count > 0)
                            //    {
                            //        ViewState["SearchPageIndexChanging"] = dt;
                            //        GridSearch.DataSource = dt;
                            //        GridSearch.DataBind();
                            //        GridSearch.Visible = true;
                            //    }
                            //    else
                            //    {
                            //        GridSearch.Visible = false;
                            //    }
                            //}                          

                            SPListItemCollection item = list.GetItems(query);
                            DataTable dtd = item.GetDataTable();
                            if (dtd != null && dtd.Rows.Count > 0)
                            {
                                ViewState["SearchPageIndexChanging"] = dtd;
                                GridSearch.DataSource = dtd;
                                GridSearch.DataBind();
                                GridSearch.Visible = true;
                            }
                            else
                            {
                                GridSearch.Visible = false;
                            }
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                GridSearch.DataSource = null;
                GridSearch.DataBind();
                lblErrMsg.Text = ex.Message;
            }
         
        }

        private string GetFieldValue(SPListItem item, string fieldName)
        {
            string strFieldValue = string.Empty;

            if (item != null && item.Fields.ContainsField(fieldName) && item[fieldName] != null)
            {
                strFieldValue = item[fieldName].ToString();
            }
            return strFieldValue;
        }


Sunday, 10 May 2015

Backup command in Powershell


I am using force command because I want to overwrite the existing site collection that I created now.

Backup-SpSite -Identity http://ibggn5456-2:7777/ -Path "D:\SiteBackupData\11052015.bak" - Force

Restore-SpSite -Identity http://ibggn5456-2:7777/ -Path "D:\SiteBackupData\11052015.back" - Force


Export-SPWeb –Identity http://ibggn5456-2:2222/ -Path "D:\SiteBackupData\PU.cmp" -Itemurl "/Lists/PU/" -Force

Import-SPWeb –Identity http://ibggn5456-2:2222/ -Path "D:\SiteBackupData\PU.cmp" -Force -IncludeUserSecurity


A complete farm backup followed by a restore:
Backup-SPFarm –Directory "D:\SiteBackupData\" -BackupMethod Full 
Restore-SPFarm –Directory "D:\SiteBackupData\" -RestoreMethod New
Back up and restore a service application:
Backup-SPFarm –Directory \\App01\SharePointBackups -BackupMethod Full –Item "Excel Services"
Restore-SPFarm –Directory \\App01\SharePointBackups -RestoreMethod New –Item "Excel Services"
Back up and restore farm configuration information only:
Backup-SPConfigurationDatabase –Directory \\App01\SharePointBackups
Restore-SPFarm –Directory \\App01\SharePointBackups –RestoreMethod Overwrite –ConfigurationOnly
Back up and restore your SharePoint content databases: 
Backup-SPFarm –Directory \\App01\SharePointBackups -BackupMethod Full –Item ContosoPortal
Restore-SPFarm –Directory \\App01\SharePointBackups -RestoreMethod New –Item ContosoPortal
Back up and restore a site collection: 
Backup-SPSite –Identity http://App01/Sites/ContosoPortal -Path \\App01\SharePointBackups\PortalSiteCollection.bak -Force
Restore-SPSite –Identity http://App01/Sites/ContosoPortal -Path \\App01\SharePointBackups\PortalSiteCollection.bak –Force
Export and import a subsite, list, or library:
Export-SPWeb –Identity http://App01/Sites/ContosoPortal/ -Path \\App01\SharePointBackups\SharedDocuments.bak -Itemurl "Shared Documents" -Force
Import-SPWeb –Identity http://App01/Sites/ContosoPortal/ -Path \\App01\SharePointBackups\SharedDocuments.bak –Force -IncludeUserSecurity







http://www.c-sharpcorner.com/uploadfile/Roji.Joy/backuprestore-of-sharepoint-2010-site-collection-using-power-shell/

http://sharepointmalaya.blogspot.in/2011/01/sharepoint-powershell-backup-and.html

For stsadm command
http://sharepointmalaya.blogspot.in/2011/01/sharepoint-stsadm-backup-and-restore.html




Monday, 4 May 2015

SharePoint 2010 Workflows Learning Links


SharePoint 2010 Workflows Learning Links

https://sergeluca.wordpress.com/2011/01/06/step-by-step-tutorial-creating-workflows-for-sharepoint-2010-step-115/


https://sergeluca.wordpress.com/2011/02/13/step-by-step-tutorial-creating-workflows-for-sharepoint-2010-retrieving-list-items-step-215/