Tuesday, May 15, 2012

How to open hyperlinks into modal dialog box in SharePoint 2010

SharePoint 2010 provides new feature "Modal dialog box". In this blog we shows how to open hyperlinks in modal dialog box using simple jquery selector.

Declaration syntax for modal dialog box is as follows

//Using the DialogOptions class.
var options = SP.UI.$create_DialogOptions();

options.title = "Dialog box title";
options.width = 300;
options.height = 500;
options.url = "PageUrl";

SP.UI.ModalDialog.showModalDialog(options);


//Using a generic object.
var options = {
    title: "Dialog box title",
    width: 300,
    height: 500,
    url: "PageUrl" };
SP.UI.ModalDialog.showModalDialog(options);


Now we put above modal dialog syntax in jquery selector

$("[href(selection attributes)'Condition']").click ( function () {
                                                                   var options = {
                                                                   title: "Dialog box title",
                                                                   width: 300,
                                                                   height: 500,
                                                                   url: $(this).attr('href')
                                                                 };
                                                                   return false;// required to override default behavior of hyperlink tag
                                                                });

We have to open link which contains the query string parameters "ShowInDialog=1", then selection condition for it
$("[href*='ShowInDialog=1']")

Attribute for selection 
!= is not equal
^= is starts with
$= is ends with
*= is contains



Example for selecting hyper links which contains query string parameter "ShowInDialog=1" 
$("[href*='ShowInDialog=1']").click ( function () {

                                                                   var options = {
                                                                   title: "Dialog box title",
                                                                   width: 300,
                                                                   height: 500,
                                                                   url: $(this).attr('href')
                                                                 };
                                                                   return false;// required to override default behavior of hyperlink tag
                                                                });







Wednesday, February 1, 2012

Modal Dialog in SharePoint 2010

Modal dialog is new feature provided by SharePoint 2010. SharePoint 2010 uses modal dialog box for add and update items, perform administrator tasks without redirect current page.


To use modal dialog box you have to include client library SP.UI.ModalDialog. syntax for calling modal dialog box is shown below

SP.UI.ModalDialog.showModalDialog({
    url: "Url Of Page",
    title: "Title of Page",
    allowMaximize: true/false,
    showClose: true/false,
    width: in pixel e.g 800,
    height: in pixel e.g 600,
    dialogReturnValueCallback: callbackfunction
    });

Modal dialog box also takes SP.UI.DialogOptions as optional structure, syntax with structure is shown below

var Dialogoptions = SP.UI.$create_DialogOptions();

options.title = "PageTitle";
options.width = 600;
options.height = 800;
options.url = "PageUrl";
dialogReturnValueCallback: callbackfunction ;

SP.UI.ModalDialog.showModalDialog(options);

or you send options using simple generic object 

var genericoptions = {
    title: "PageTitle";,
    width: 800,
    height: 600,
   dialogReturnValueCallback: callbackfunction ,
    url: "PageUrl";};

SP.UI.ModalDialog.showModalDialog(options);


//Call back function syntax
function callbackfunction (dialogResult, returnValue) {

 } 



Monday, January 23, 2012

SPLongOperation error for ItemAdding Event In SharePoint 2010



We recently upgrade one of our project from SharePoint 2007 to SharePoint 210. In that project we user event handler for list. In ItemAdding event we use to create new site which takes times for creation. So we use SPLongOperation to handle it  but in SharePoint 2010 its same code gives error for "Object reference null" for SPLongOperation being statement.
So we had following workaround for this problem.

Create Web Part with following Code and add this web part to publishing Page

protected override void CreateChildControls(){
 if (this.Page.Request.QueryString["Processid"] != null)
            {           

                using (SPLongOperation ctx = new SPLongOperation(this.Page))
                {
                    try
                    {
                        ctx.LeadingHTML = "Please wait while your operation is being executed.";
                        ctx.TrailingHTML = "Site is being created. Please wait....";
                        ctx.Begin();

                        System.Threading.Thread.Sleep(5000);
                        string eid = this.Page.Request.QueryString["Processid"].ToString();
                        int count = 1;
                        while (true)
                        {
                            using (SPWeb web = SPContext.Current.Site.OpenWeb(SPContext.Current.Web.ID))
                            {
                                if (web.Properties[eid].ToString() != "Completed" && count < 18)
                                {

                                    System.Threading.Thread.Sleep(5000);
                                    count++;
                                }
                                else
                                    break;
                            }
                        }
                        ctx.End(this.Page.Request.QueryString["h"].ToString());
                    }
                    catch (Exception ex)
                    {
                        this.lbl.Text = ex.Message.ToString() + Environment.NewLine + ex.StackTrace.ToString() ;
                    }
                }
            }
}

In event handler modify ItemAdding event as follows

 public override void ItemAdding(SPItemEventProperties properties)
        {
            base.ItemAdding(properties);
            string guid
                = string.Format("ProcessId{0}_{1}", DateTime.Now.ToString("MMddyyyy"), Guid.NewGuid().ToString());
            Thread thread = new Thread(() => FunctionName(properties,guid));
            thread .Start();

            properties.Status = SPEventReceiverStatus.CancelNoError;
            properties.Cancel = true;
            SPUtility.Redirect({Url of page on which out put above webpart}, SPRedirectFlags.Default, _currentContext,string.Format ("Processid={0}&h={1}",guid , properties.RelativeWebUrl));
        }

Hope this work for you also

Tuesday, January 17, 2012

Using PowerShell Command for Visual Upgrade

Upgrade Visual from SharePoint 2007 to SharePoint 2010 after restoring Content Database on SharePoint 2010 Server.

When we restore content database in SharePoint 2010 from SharePoint 2007, it required to upgrade the Visual to Version 4. Following command will update all the site and sub-sites for provided content database.

$ContentDatabaseName = Get-SPContentDatabase WSS_Content_SharePoint_Database_Restore

$ContentDatabaseName.Sites | Get-SPWeb -limit all | ForEach-Object {$_.UIversion = 4; $_.UIVersionConfigurationEnabled = $false; $_.update()}



Friday, December 30, 2011

How to create workflow in Visio and import it in Sharepoint Designer 2010 - Part 2

In previous blog we saw how to create and export the workflow diagram in Visio 2010 ( How to create workflow in Visio and import it in Sharepoint Designer 2010 - Part 1 ). In this blog we import workflow file in SharePoint Designer 2010.

  1. Open SharePoint Designer 2010 -> Click on "Open Site" -> In open site window enter site URL on which you want to import the workflow.
  2. Click on "Workflows" in Navigation -> Click on "Import from Visio" button from top ribbon -> In Import workflow from Visio Drawing browse the path of export file and click on Next button.
  3. In this screen Click on List Workflow and from drop down select "Reimbursement Request" list and click on finish.
  4. After click on finish you got following workflow view now we have to set the condition and values for this imported workflow.

    1. Click on "Value" in top if statement , here we have to select expense and specifies the limit after which approval is required for it. set the value as shown in fig. below


    2. Set approval attributes as shown in fig. below


    3. Click on value link after "Is Approved?"  from pop up window set approval status field from field from source drop down and set condition equals to approved. If approval status is equal to approved then you have to inform user that his request has been approved by department head. for that set following values as shown in fig. below. and for update item , select current item, add Authorized field and set its values to Yes.

    4. Repeat above step for remaining else parts with appropriate messages.
  5. Save current workflow and click on "Check for Errors" button which is on top of ribbon. if workflow complied successfully then pop up message shows "The workflow contains no errors". Go to start options of workflow and check on "Start workflow automatically when item is created." and click on button publish button to publish workflow in selected list.
  6.  
After this step we had workflow which is published on site, now go to site and add item with Expense amount greater than Rs. 200.

Wednesday, December 28, 2011

Content type hub problem with Blank Site Template

As I mentioned in how to deploy content type hub in my previous blog ("Content Type Hubs Publishing in Sharepoint 2010"), after following blog content type is not appearing on site may required to activate the Taxonomy feature on that site, following command required to activate the feature

STSADM -o activatefeature -id 73EF14B1-13A9-416b-A9B5-ECECA2B0604C -url http:// -force

Power Shell Command
Enable-SPFeature -id 73EF14B1-13A9-416b-A9B5-ECECA2B0604C -URL

Hope this work for you also....


Good luck :-)

Wednesday, December 21, 2011

How to setup content type publishing hub in SharePoint 2010

What is Content Type Hub ?
Content type hub is new feature of SharePoint 2010 to manage content type centrally (Content Type Gallery) and publish them to subscribed sites.

Prerequisite :
  1. Create two web application on two separate port number. we called site A as publisher and site b as subscribed site.
  2. Create content type on site A called "Content Type Hub Demo" of document base type. 

Create service to deploy content type hub
 

  1. Open SharePoint 2010 Central Administration - > Click on Manage service applications under Application Management section -> Click on New and select Managed Metadata Service


  2. On "Create New Managed Metadata Service" window change following values
    Name : Content Type Hub
    Database Name : Content_Type_Hub_Database
    Use existing application pool: SharePoint Web Service Default
    : "Enter the url of web site which going to act as publisher for content type". Click on "Ok" button

How to deploy content type hub ?To deploy content type hub on site you required to activate "Content Type Syndication Hub" feature on publisher site which in Site Collection features.


After activating feature go to content type gallery of site, click on Site Actions -> Site Settings -> under Galleries section you find "Site Content Types" click on it. On site content types page select "Content Type Hub Demo" content type.

In Settings section of Content type Click on "Manage publishing for this content type" and On Content type publishing select "Publish" and click on "OK" button.
After this we required to run Timer jobs manually first time to publish the content type. Go to "SharePoint 2010 Central Administration" -> Click on Monitoring -> Click on Review job definitions.

In Job Definitions run the jobs in following order
1.Content type hub
2.Content Type Subscriber job for publishing site
3.Content Type Subscriber job for subscriber sites.

Go to subscriber site and Content type gallery you find the "Content Type Hub Demo" content type.






Start With MVC Application Part 1

Before we starting to create MVC Application we required customer table on which we create our application. So first create customer table...