Friday, 27 November 2015

Error - URL Name can not contain any of the following characters


Assume that you type a page name, such as “Text with space” in the New item form in a pages library in SharePoint Server 2013 to create a new page. After you create the page, the automatically generated URL is inconsistent with the preview URL. For example, the preview URL may be displayed in a label as follows:



Solution:

1. Go to "Site Settings". 
2. Click on "Page Layout and Site Template Settings" under "Look and Feel".
3. Scroll down and check option "Convert blank spaces in page name to'-'".

Case 2

If you have installed SharePoint April to September Cumulative Update package 2015 then you might face above error even you have checked the option given in solution above. 

Solution: 

This issue is resolved in October 2015 Cumulative Update. Reference Links are:
https://support.microsoft.com/en-us/kb/3085567
http://thesharepointfarm.com/2015/04/ms15-036-and-april-2015-cu-createpage-issue/

Wednesday, 25 November 2015

Enable SmallSearchbox in Search result page SharePoint

Recently I was given a task to enable Search Bar in Search result page of SharePoint. If you meet such requirement here is the simple solution:

Case 1: You have not configured search service:

In this case your search will open SharePoint default result page: osssearchresults.aspx.

You can find this page in "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS".

Open this page and in "PlaceHolderSearchArea" ContentPlaceHolder add below lines of code:

 <div id="searchInputBox">
<SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox" />                                 
</div>

save the file.

Refresh your search page and you will see the search bar in header section.

Case 2: You have configured Search service:

In this case your search will open pages/result.aspx page for search result.
But we can't add our code in this page. We need to add our block of code in the page layout of this page.

You can find that in "Site settings->masterpages & page layouts -> SearchResult.aspx"
Download this page.

Open this page and in "PlaceHolderSearchArea" ContentPlaceHolder add below lines of code:

 <div id="searchInputBox">
<SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox" />                                 
</div>

save the file.

If you refresh your  page and you get error "Sorry, Something went wrong", Please check this blog.


SearchResult.aspx: Code blocks are not allowed in this file.

Recently I was working with search bar in search result page where I encounter below error:

Sorry, Something went wrong
An error occurred during the processing of /sites/search/_catalogs/masterpage/searchresults.aspx. Code blocks are not allowed in this site.


Solution:

1. Open Web.config
2. find <PageParserPath>
3. Add below line in it.

<PageParserPath VirtualPath="/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true" />

Tuesday, 24 November 2015

SharePoint 2013: August 2015 Cumulative Update Package Installation Failed

Recently I was installing SharePoint 2013 Cumulative Update August 2015 when I encounter below error couple time.

"The installation of this package failed"

Solution:

The best workaround for this issue is to simply run the installation package 3 times. The package will fail to install with the above error on the first two attempts, but should be successful on the third attempt.  The installation will not be corrupt and there are no other known issues once you have the update package successfully installed.

Original Source: http://blogs.msdn.com/b/tehnoonr/archive/2015/08/28/sharepoint-2013-august-2015-cumulative-update-package-fails-to-install.aspx

Error : Mount-SPContentDatabase : This content database has a schema version which is not supported in this farm

While restoring a database from one farm to other I encounter below error:

Mount-SPContentDatabase : This content database has a schema version which is not supported in this farm

Reason:

When I check the version of current SharePoint and restore database version they were different.

You can check current SharePoint version as follow:

Go to Central Administration -> System Settings-> Servers-> Manage Servers in the farm.

You can check the version of the database in version table of content database.

You can check SharePoint build version here.

Solution:

You need to install updates in your new farm and when your SharePoint and database version are same you can Mount database to new farm.

SharePoint 2013 Build versions

SharePoint 2013

Build Number
Build Name
Component
Information Link
Download Link
Notes
15.0.4128.1014 Beta SharePoint Foundation 2013   Download Bugs, Notes, & Regressions
15.0.4128.1014 Beta SharePoint Server 2013   Download
15.0.4128.1014 Beta Project Server 2013   Download  
​ ​ ​ ​ ​ ​
​15.0.4420.1017 ​RTM ​​SharePoint Foundation 2013 ​ ​Download ​Bugs, Notes, & Regressions
​​15.0.4420.1017 ​RTM ​SharePoint Server 2013 ​ ​Download ​
​​15.0.4420.1017 ​RTM ​Project Server 2013 ​ ​Download ​
​ ​ ​ ​ ​ ​
​15.0.4433.1506 ​December 2012 Hotfix ​SharePoint Server 2013 ​KB2752058 ​Download ​Bugs, Notes, & Regressions
​15.0.4433.1506 ​December 2012 Hotfix ​SharePoint Server 2013 (coreserver) ​KB2752001 ​Download ​
​ ​ ​ ​ ​ ​
​15.0.4481.1005 ​March 2013 Public Update ​SharePoint Foundation 2013 ​KB2768000 ​Download ​Bugs, Notes, & Regressions
​​15.0.4481.1005 ​​March 2013 Public Update ​SharePoint Server 2013 ​KB2767999 ​Download ​
​​15.0.4481.1005 ​​March 2013 Public Update ​Project Server 2013 ​KB2768001 ​Download ​
​ ​ ​ ​ ​ ​
​15.0.4505.1002 ​April 2013 CU ​​SharePoint Foundation 2013 ​KB2751999 ​Download Bugs, Notes, & Regressions
​15.0.4505.1005 ​​April 2013 CU ​SharePoint Server 2013 ​KB2726992 ​Download ​
​15.0.4505.1005 ​April 2013 CU ​Project Server 2013 ​KB775426 ​Download ​
​ ​ ​ ​ ​ ​
​15.0.4517.1003 ​June 2013 CU ​SharePoint Foundation 2013 ​KB2817346 ​Download ​Bugs, Notes, & Regressions
​15.0.4517.1005 ​June 2013 CU ​​SharePoint Server 2013 ​KB2817414 ​Download ​
​ ​June 2013 CU ​Project Server 2013 ​KB2817415 ​Download ​
​ ​ ​ ​ ​ ​
​15.0.4535.1000 ​August 2013 CU ​​SharePoint Foundation 2013 ​KB2817517 ​Download ​Bugs, Notes, & Regressions
​ ​​August 2013 CU ​SharePoint Server 2013 ​KB2817616 ​Download ​
​ ​​August 2013 CU ​Project Server 2013 ​KB2817615 ​Download ​
​ ​ ​ ​ ​ ​
​15.0.4551.1001 ​October 2013 CU ​SharePoint Foundation 2013 ​KB2825674 ​Download ​Bugs, Notes, and Regressions
​15.0.4551.1005 ​October 2013 CU ​SharePoint Server 2013 ​KB2825647 ​Download ​
​ ​October 2013 CU ​Project Server 2013 ​ ​ ​
​ ​ ​ ​ ​ ​
​15.0.4551.1508 ​December 2013 CU ​SharePoint Foundation 2013 ​KB2849961 ​Download ​​Bugs, Notes, and Regressions
​15.0.4551.1511 ​ ​SharePoint Server 2013 ​KB2850024 ​Download ​
​15.0.4551.1508 ​ ​Project Server 2013 ​KB2837668 ​Download ​
​ ​ ​ ​ ​ ​
​15.0.4569.1000* ​Service Pack 1 ​SharePoint Foundation 2013 ​KB2817439 ​Download ​Bugs, Notes, and Regressions
​ ​ ​SharePoint Server 2013 ​KB2817429 ​Download ​
​ ​ ​Project Server 2013 ​KB2817434 ​Download ​
​ ​ ​ ​ ​ ​
​15.0.4571.1502* ​Service Pack 1 Mark 2 ​SharePoint Foundation 2013 ​KB2880551 ​Download ​Bugs, Notes, and Regressions

​​ ​SharePoint Server 2013 ​KB2880552 ​Download ​

​​ ​Project Server 2013 ​KB2880553 ​Download ​
​ ​ ​ ​ ​ ​
​​15.0.4605.1000 ​April 2014 CU ​​SharePoint Foundation 2013 KB2863892 ​Download ​​Bugs, Notes, and Regressions
​ ​ ​​SharePoint Server 2013 ​KB2878240 ​Download ​
​ ​ ​Project Server 2013 KB2880484 Download ​
​ ​ ​ ​ ​ ​
​15.0.4615.1001 ​MS14-022 ​SharePoint Foundation 2013 ​KB2952166 ​Links in KB ​Bugs, Notes, and Regressions
​ ​ ​SharePoint Server 2013 ​KB2952166 ​Links in KB ​
​ ​ ​Project Server 2013 ​KB2952166 ​Links in KB ​
​ ​ ​ ​ ​ ​
15.0.4617.1000 ​June 2014 CU SharePoint Foundation 2013 ​KB2881063 ​Download ​Bugs, Notes, and Regressions
​ ​ ​SharePoint Server 2013 KB2881061 ​Download ​
​ ​ ​Project Server 2013 KB2881062 ​Download ​
​ ​ ​ ​ ​ ​
​ 15.0.4631.1001 ​July 2014 CU ​SharePoint Foundation 2013 ​KB2882999 ​Download ​​Bugs, Notes, & Regressions
​ ​ ​​SharePoint Server 2013 ​KB2882989 ​Download
​ ​ ​Project Server 2013 ​KB2882990 ​Download ​
​ ​ ​ ​ ​ ​
​15.0.4641.1001 ​August 2014 CU ​SharePoint Foundation 2013 ​KB2883081 ​Download ​Bugs, Notes, & Regressions
​ ​ ​SharePoint Server 2013 (1/5) ​KB2760213 ​Download ​
​ ​ ​​SharePoint Server 2013 (2/5) ​KB2880559 ​Download ​
​ ​ ​​SharePoint Server 2013 (3/5) ​KB2883078 Download ​
​ ​ ​​SharePoint Server 2013 (4/5) ​KB2883085 ​Download ​
​ ​ ​​SharePoint Server 2013 (5/5) ​KB2883086 ​Download ​
​ ​ ​Project Server 2013 ​KB2883083 ​Download ​
​ ​ ​ ​ ​ ​
​15.0.4649.1001 ​September 2014 CU ​SharePoint Foundation 2013 ​KB2883087 ​Download ​Bugs, Notes, & Regressions
​ ​ ​SharePoint Server 2013 ​KB2883068 ​Download ​
​ ​ ​Project Server 2013 ​KB2883072 ​Download ​
​ ​ ​ ​ ​ ​
​15.0.4659.1001 ​October 2014 CU ​SharePoint Foundation 2013 ​KB2889946 ​Download ​​Bugs, Notes, & Regressions
​ ​ ​SharePoint Server 2013 (1/3) ​KB2899469 ​Download ​
​ ​ ​SharePoint Server 2013 (2/3) ​KB2880962 ​Download ​
​ ​ ​SharePoint Server 2013 (3/3) ​KB2880485 ​Download ​
​ ​ ​Documentum Connector ​KB2752098 ​Download ​
​ ​ ​Project Server 2013 ​KB2889959 ​Download ​
​ ​ ​ ​ ​ ​
​15.0.4667.1000 ​November 2014 CU ​SharePoint Foundation 2013 ​KB2899468 ​Download ​Bugs, Notes, and Regressions
​ ​ ​​SharePoint Server 2013 ​KB2889944 ​Download ​
​ ​ ​Project Server 2013 ​KB2889949 ​Download ​
​ ​ ​ ​ ​ ​
​15.0.4675.1000 ​December 2014 CU ​SharePoint Foundation 2013 ​KB2910945 ​Download ​Bugs, Notes, and Regressions
​ ​ ​SharePoint Server 2013 ​KB2910938 Download​ ​
​ ​ ​Project Server 2013 ​KB2910911 ​Download ​
​ ​ ​ ​ ​ ​
​15.0.4693.1001 ​February 2015 CU ​​SharePoint Foundation 2013 ​KB2920801 Download ​Bugs, Notes, and Regressions
​ ​ ​​SharePoint Server 2013 ​KB2920804 ​Download ​
​ ​ ​​Project Server 2013 ​KB2920796 ​Download ​
​ ​ ​ ​ ​ ​
​15.0.4701.1001 ​March 2015 CU ​SharePoint Foundation 2013 ​KB2956159 ​Download ​Bugs, Notes, and Regressions
​ ​ ​SharePoint Server 2013 ​KB2956166 ​Download ​
​ ​ ​Project Server 2013 ​KB2956162 ​Download ​
​ ​ ​ ​ ​ ​
​15.0.4711.1000 ​April 2015 CU ​SharePoint Foundation 2013 ​KB2965261 ​Download ​Bugs, Notes, and Regressions
​ ​ ​​SharePoint Server 2013 ​KB2965266 ​Download ​
​ ​ ​Project Server 2013 ​KB2965263 ​Download ​
​ ​ ​ ​ ​ ​
​15.0.4719.1002 ​May 2015 CU ​SharePoint Foundation 2013 ​​​Bugs, Notes, and Regressions
​ ​ ​SharePoint Server 2013 ​KB3039780 ​
​ ​ ​Project Server 2013 ​KB3039753 ​
​ ​ ​ ​ ​ ​
​15.0.4727.1001 ​June 2015 CU ​SharePoint Foundation 2013 ​KB3054864 ​Download ​Bugs, Notes, and Regressions
​ ​ ​SharePoint Server 2013 ​KB3054866 ​Download ​
​ ​ ​Project Server 2013 ​KB3054865 ​Download ​
​ ​ ​ ​ ​ ​
​​15.0.4737.1001 ​July 2015 CU ​SharePoint Foundation 2013 ​Bugs, Notes, and Regressions
​ ​ ​SharePoint Server 2013 ​
​ ​ ​Project Server 2013 ​
​ ​ ​ ​ ​ ​
​​​15.0.4745.1001 ​August 2015 CU ​​SharePoint Foundation 2013 ​KB3055004 ​​Bugs, Notes, and Regressions
​ ​ ​SharePoint Server 2013 ​
​ ​ ​​Project Server 2013 ​Download ​
​ ​ ​ ​ ​ ​
​15.0.4753.1000 ​September 2015 CU
SharePoint Foundation 2013
​KB2975894 ​Bugs, Notes, and Regressions
​ ​ ​SharePoint Server 2013 ​
​ ​ ​Project Server 2013 ​
​ ​ ​ ​ ​ ​
​15.0.4763.1000 ​October 2015 CU ​SharePoint Foundation 2013 ​KB3085488 ​Download ​​Bugs, Notes, and Regressions
​ ​ ​SharePoint Server 2013 ​KB3085492 ​Download ​
​ ​ ​Project Server 2013 ​KB3085489 ​Download ​
​ ​ ​ ​ ​ ​
​15.0.4771.1000 ​November 2015 CU ​SharePoint Foundation 2013 ​KB3101368 ​Download ​Bugs, Notes, and Regressions
​ ​ ​SharePoint Server 2013 ​KB3101373 ​Download ​
​ ​ ​Project Server 2013 ​KB3101369 ​Download ​

Original Source: http://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=346

Monday, 9 November 2015

check which control fired post back at pageload

If you want to know which controlled fired post back at page load, here is some sample code.

1) for link button:

string ctrlname = Page.Request.Params["__EVENTTARGET"];
                        if ((!string.IsNullOrWhiteSpace(ctrlname)) && ctrlname.EndsWith("lnkSelect"))
                        {
                            LinkButton lnk1 = Page.FindControl(ctrlname) as LinkButton;
                         }

2) for Image button and Button:

protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
            Response.Write(getPostBackControlName());
    }

   
    private string getPostBackControlName()
    {
        Control control = null;
        //first we will check the "__EVENTTARGET" because if post back made by       the controls
        //which used "_doPostBack" function also available in Request.Form collection.
        string ctrlname = Page.Request.Params["__EVENTTARGET"];
        if (ctrlname != null && ctrlname != String.Empty)
        {
            control = Page.FindControl(ctrlname);
        }
        // if __EVENTTARGET is null, the control is a button type and we need to
        // iterate over the form collection to find it
        else
        {
            string ctrlStr = String.Empty;
            Control c = null;
            foreach (string ctl in Page.Request.Form)
            {
                //handle ImageButton they having an additional "quasi-property" in their Id which identifies
                //mouse x and y coordinates
                if (ctl.EndsWith(".x") || ctl.EndsWith(".y"))
                {
                    ctrlStr = ctl.Substring(0, ctl.Length - 2);
                    c = Page.FindControl(ctrlStr);
                }
                else
                {
                    c = Page.FindControl(ctl);
                }
                if (c is System.Web.UI.WebControls.Button ||
                         c is System.Web.UI.WebControls.ImageButton)
                {
                    control = c;
                    break;
                }
            }
        }
        return control.ID;

    }
}

New instance of this workflow template are currently disallowed

When you try to start workflow programmatically you might encounter following error

New instance of this workflow template are currently disallowed

The root cause of this error is multiple version of workflow is associated with list. You can check it in List Seeitngs -> Workflow settings.

Here is the code that generates the error:

public static void StartWorkflow(SPListItem listItem, SPSite spSite, string wfName)
        {
            SPList parentList = listItem.ParentList;
            SPWorkflowAssociationCollection associationCollection = parentList.WorkflowAssociations;
            foreach (SPWorkflowAssociation association in associationCollection)
            {
                if (association.Name.ToString().ToLower() == wfName.ToLower())
                {
                    association.AssociationData = string.Empty;
                    // this line throws error for old instance of workflow
                    spSite.WorkflowManager.StartWorkflow(listItem, association, association.AssociationData);

                }
            }
        }

Resolution:

SPWorkflowAssociation class has a property called Enabled. It check whether new instance for this workflow is allowed or not. We will use it in our code block to stop the workflow to start.

Here is the error free code:

public static void StartWorkflow(SPListItem listItem, SPSite spSite, string wfName)
        {
           
                SPList parentList = listItem.ParentList;
                SPWorkflowAssociationCollection associationCollection = parentList.WorkflowAssociations;
                foreach (SPWorkflowAssociation association in associationCollection)
                {
                    if (association.BaseTemplate.Name.ToString().ToLower() == wfName.ToLower())
                    {
                        if (association.Enabled) // check if new instance is allowed.
                        {
                            //spSite.AllowUnsafeUpdates = true;
                            var data = association.AssociationData;
                            spSite.WorkflowManager.StartWorkflow(listItem, association, data);
                            //spSite.AllowUnsafeUpdates = false;
                        }
                    }
                }
            }

Tuesday, 3 November 2015

General Code Review

Code Review :- General 
1. Remove the  commented code
2. Variable name should not be contain "_".
3. Query should be in separate class.
4. Use Common log error when handle the exception
5. Use String.isNullorWhiteSpace instead of String.isNullorEmpty
6. Use Using Statement for variable scope should be limited.
7.  Remove unnecessary if ... else ...

e.g.   if (dtTasksAll != null && dtTasksAll.Rows.Count > 0)
{
            gv.DataSource = dtTasksAll;
            gv.DataBind();
        }
        else
        {
gv.EmptyDataText = "No New Tasks found";
lblviewimg.Visible=false;
gv.DataSource = dtTasksAll;
gv.DataBind();
}

Optimized code :-
if(dtTasksAll == null)
{
gv.EmptyDataText = "No New Tasks found";
lblviewimg.Visible=false;
}
gv.DataSource = dtTasksAll;
gv.DataBind();

8. Terminate loop as soon as possible

e.g.
foreach (SPUser user in group.Users)
{
if (!string.IsNullOrEmpty(user.Email))
{
MailTo += MailTo == string.Empty ? user.Email : "," + user.Email;
}
}

Optimized code :-
foreach (SPUser user in group.Users)
{
if (string.IsNullOrWhiteSpace(user.Email)) Continue;
MailTo += MailTo == string.Empty ? user.Email : "," + user.Email;
}

The "Mark as Decorative" Feature in SharePoint: A Small Toggle With a Big Accessibility Impact

If you've spent any time building pages in SharePoint Online, you've probably noticed a new checkbox tucked inside the Accessibility...