Monday, December 16, 2013

Unknown server tag 'SharePoint:ScriptBlock'.

Error: Unknown server tag 'SharePoint:ScriptBlock'.

Issue: You will get above error when you use the application page in SharePoint 2013 using <SharePoint:ScriptBlock> and try to use that in SharePoint 2010.

Cause: ScriptBlock class is not available in SharePoint 2010 & 2007.

Resolution: Replace the block with <script type="text/javascript">

Sunday, December 15, 2013

This operation can be performed only on a computer that is joined to a server farm by users who have permissions in SQL Server to read from the configuration database. To connect this server to the server farm, use the SharePoint Products Configuration Wizard, located on the Start menu in Microsoft SharePoint 2010 Products.

Error: This operation can be performed only on a computer that is joined to a server farm by users who have permissions in SQL Server to read from the configuration database. To connect this server to the server farm, use the SharePoint Products Configuration Wizard, located on the Start menu in Microsoft SharePoint 2010 Products.

Cause: Got above error when I tried to access my SharePoint site and Central administration. The error says that current user is not able to access the database. Everything was working fine until I've crashed my VMWare and restarted.

Resolution:
1. Open Services.msc
2. Restarted SQL Server (SHAREPOINT) service
3. Noticed that the following services was disabled. Enabled both the service.
SQL Server Agent (SHAREPOINT)
SQL Server Browser

Friday, December 6, 2013

Close modal dialog after page validation passes

Requirement:
To open the default Create Group (newgrp.aspx) page as a dialog box from our custom page on a button click. Close the modal dialog box after page submits.
We created a copy of newgrp.aspx page and used that page to achieve this.

Issues we had:
1. Default “create group” page redirects to the people.aspx page after successful page submission.
2. Closing the dialog on Window.unload worked fine, but the dialog got closed even when the validation fails as validation refresh the page.

Solution:
Create an HTTPModule to check the current page and previous page details though HTTP events. Below is the HttpModule code we used to achieve this.

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DSPModule
{
    public class DynamicModule : IHttpModule
    {

        string strParentPageURL = string.Empty;
        string strCurrentPageURL = string.Empty;

        public DynamicModule()
        {
        }

        public String ModuleName
        {
            get { return "DSPDynamicModule"; }
        }

        // In the Init function, register for HttpApplication events by adding your handlers.
        public void Init(HttpApplication context)
        {
            context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
        }
        void context_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            HttpContext currentContext = HttpContext.Current;
            Page page = currentContext.CurrentHandler as Page;
            if (page != null)
            {
                page.LoadComplete += new EventHandler(page_LoadComplete);
            }
        }
        void page_LoadComplete(object sender, EventArgs e)
        {        
             HttpContext currentContext = HttpContext.Current;
             if(currentContext.Request.UrlReferrer != null)
                strParentPageURL = currentContext.Request.UrlReferrer.ToString().Trim().ToUpper();

             strCurrentPageURL = currentContext.Request.Url.AbsolutePath.ToString().Trim().ToUpper();
             if (strParentPageURL.Contains("/_LAYOUTS/DSPHANDLER/DSPNEWGRP.ASPX") && strCurrentPageURL.Contains("/_LAYOUTS/PEOPLE.ASPX") && strParentPageURL.Contains("?ISDLG=1"))
             {
                 HttpContext.Current.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup();</script>");
                 HttpContext.Current.Response.Flush();
                 HttpContext.Current.Response.End();
             }
        }
        public void Dispose()
        {

        }
    }
}

Make sure that you add the following entry in the web.config file of the web application at path "configuration/system.webServer/modules"
<add name="DSPDynamicModule" type=" DSPModule.DynamicModule, DSPModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=fa63464975c1a198" />

Feel free to discuss if you have better way of doing this.