MY ACCOUNT  |  LOGIN

Sales: 1-888-936-8638

ORDER ONLINE >

 

  


    AJAX
    Sharepoint
    Silverlight



Using Essential Studio ASP.NET controls in SharePointWebPart

What is SharePoint?

SharePoint is an enterprise information portal, from Microsoft, that can be configured to run Intranet, Extranet and Internet sites. Microsoft Office SharePoint Server 2007 allows people, teams and expertise to connect and collaborate. A SharePoint enterprise portal is composed of both SharePoint Portal and Windows SharePoint Services, with SharePoint being built upon WSS. WSS is typically used by small teams, projects and companies. SharePoint Server is designed for individuals, teams and projects within a medium to large company wide enterprise portal.

Essential Studio Sharepoint Samples

 Tools Web : Download (6.82 KB)
 Grid Web : Download (4.66 KB)
 Chart Web : Download (4.44 KB)
Microsoft Office SharePoint Server 2007

Microsoft Office SharePoint Server 2007 is a collaborative enterprise portal that is built upon WSS 3.0. MOSS 2007 allows people, teams and expertise to connect and collaborate.

The main components of SharePoint 2007 are collaboration, portals, enterprise search, enterprise content management, business process and forms, and business intelligence.

Windows SharePoint Services 3.0

Windows SharePoint Services 3.0 is the platform on which all SharePoint Products and Technologies are built. WSS 3.0 is suitable for small teams, projects and organizations.

WSS’s project collaboration, document workspace, meeting sub-site, and discussion board features allow individuals and small teams to collaborate and share information online.

Web Parts

SharePoint allows information workers to create powerful personalized interfaces by simply dragging and dropping pre-defined Web Part Components. Web Parts are components that enable non programmers to gather information they care about and customize the appearance of Web pages. For example, one Web Part might display a user's appointment calendar; another might create a graph showing current sales figures; and a third might show a list of new business topics, each of which functions as a link to a video or audio presentation. Developers can create these Web Part components and make them available to SharePoint users, letting them build customizable pages that meet their needs.

Creating a Simple Web Part

Web Parts are based on ASP.NET Web Form Controls. We can create Web Parts in C# or Visual Basic .NET by using the Web Part Library template in Visual Studio .NET.

To create a new Web Part Library project

  • Start Visual Studio .NET.
  • On the File menu, point to New, and then click Project.
  • In the New Project dialog box, click Visual C# Projects, and then select the Web Part Library template.
  • If you want to create a Visual Basic .NET project, select the Web Part Library template from Visual Basic Projects instead.
  • Type the name and specify the location for the project files, and then click OK.
Adding References

Here we have to compulsorily add Microsoft.SharePoint.dll, System.Xml.dll and then we have to add necessary references to the Project,

  • On the Project menu, click Add Reference.
  • On the .NET tab, select the Windows SharePoint Services, System.Xml, Syncfusion assemblies and other necessary assemblies.
  • Click OK.
Strong naming the assembly

Web Parts are designed to be distributed over the Internet or an intranet. For security reasons when creating a custom Web Part, we must strongly name it to ensure that the part can be trusted by the users.

A strong name consists of the assembly's identity plus a public key and a digital signature. We can use the Strong Name tool (sn.exe) to manage keys, generate signatures, and verify signatures. This tool is installed with the .NET Framework SDK when we install Visual Studio .NET.

To strongly name the assembly

We have to create a file containing the key pair. From a command prompt on the drive where we installed Visual Studio .NET, type the following:

sn.exe -k c:\keypair.snk

Note: We can use any path, as long as we refer that path in the following steps.

In the Solution Explorer, double-click AssemblyInfo.cs in the project and include the following line:

[assembly: AssemblyKeyFile("c:\\keypair.snk")]

Defining the logic and rendering of the Web Part

After completing the previous steps, we can define the logic and rendering for the Web Part. For this part, we have to write some basic ASP.NET code to create the controls. Please refer the below code snippet which illustrates this:

	        
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using Syncfusion.Web.UI.WebControls.Grid.Grouping;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Data.OleDb; 

namespace Grid_Web_SimpleWebPart
{
   [Guid("aea5e245-4a77-44f8-a1c8-0fed68e1cbde")]
    public class Grid_Web_SimpleWebPart :
        	System.Web.UI.WebControls.WebParts.WebPart
    {
        public Grid_Web_SimpleWebPart()
        {
            this.ExportMode = WebPartExportMode.All;
        }
        private GridGroupingControl GridGroupingControl1;
        private OleDbDataAdapter adaptor;
        private OleDbConnection conn;

        protected override void CreateChildControls()
        {
          base.CreateChildControls();
         this.EnsureUpdatePanelFixups();
         ScriptManager scriptHandler = new ScriptManager();
         scriptHandler.ID = "ScriptManager1";
         UpdatePanel up = new UpdatePanel();
         up.ID = "UpdatePanel1";
         up.ChildrenAsTriggers = true;
         up.UpdateMode = UpdatePanelUpdateMode.Conditional;
         this.Controls.Add(scriptHandler);
         this.Controls.Add(up);
         this.GridGroupingControl1 = new GridGroupingControl();
         this.GridGroupingControl1.ID = "GridGroupingControl";
         this.GridGroupingControl1.AutoFormat = "Office 2003 Blue";
         this.GridGroupingControl1.DataSource = GetData();
         NavigatorBar navigator = new NavigatorBar();
         NavigatorBar.AddDefaultNavigatorBarButtons(navigator);
         this.GridGroupingControl1.ButtonBars.Add(navigator);
         up.ContentTemplateContainer.Controls.Add
		    (this.GridGroupingControl1);

        }
        private DataTable GetData()
        {
            DataTable table = newDataTable();

            string connString = @"provider = microsoft.jet.oledb.4.0;
            data source =" + "C:\\Inetpub\\wwwroot\\wss\\VirtualDirectories\\80
            \\App_Data\\NWIND.MDB";
            conn = new OleDbConnection(connString);
            try
            {
                adaptor = new OleDbDataAdapter
				 ("SELECT EmployeeID, FirstName, 
                LastName, Title, Address, City, Region, Country  FROM Employees",
                conn);
                adaptor.Fill(table);               
            }
            catch (OleDbException ex)
            {
                this.GridGroupingControl1.WarningMessage = ex.Message.ToString();
            }
            return table;
        }
        private void EnsureUpdatePanelFixups()
        {
            if (this.Page.Form != null)
            {
                string formOnSubmitAtt = 
				    this.Page.Form.Attributes["onsubmit"];
                if (formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
                {
                    this.Page.Form.Attributes["onsubmit"] = 
                    "_spFormOnSubmitWrapper();";
                }
            }
            ScriptManager.RegisterStartupScript(this, 
            typeof(Grid_Web_SimpleWebPart),
			"UpdatePanelFixup", 
            "_spOriginalFormAction = document.forms[0].action; 
            _spSuppressFormOnSubmitWrapper=true;", true);
        }
        
    }
}

Deploying the WebPart

After implementing the above steps, right click on the SolutionExplorer and Deploy the solution. It will automatically do the following:

  1. First it will build the project and create the webpart assembly.
  2. Next it will add a solution folder which contains .webpart file to the build output path.
  3. Register the webpart assembly as a SafeControl.
  4. Restart the IIS to update the changes.
  5. Import the webpart into the WebParts gallery.
Register the webpart assembly as a SafeControl

To confirm the registration, open the web.config file from the following location and check for the below code:

C:\Inetpub\wwwroot\wss\VirtualDirectories\80

<SafeControl Assembly="Grid_Web_SimpleWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5" Namespace="Grid_Web_SimpleWebPart" TypeName="Grid_Web_SimpleWebPart" Safe="True" />

It is necessary that, the Syncfusion assemblies should also be registered as a SafeControl. To do so, add the following lines in the <SafeControl> block of the web.config file:

<SafeControl Assembly="Syncfusion.Grid.Grouping.Web, Version=6.302.0.6, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89" Namespace="Syncfusion.Web.UI.WebControls.Grid.Grouping" TypeName="*" Safe="True" />
To view the imported WebPart, we have to follow the below steps

1. Open the Home page of Microsoft Office SharePoint Server 2007.

2. Navigate through Site Actions -> Site Settings -> Modify All Site Settings.

3. It will open the following page. Select "Web Part" to view the Web Part gallery.

4. The below is the Web Part gallery, where all the Web Parts are imported. Click on the Web Part, we have created.

5. Web Part Preview of our Web Part.

Samples
Tools WebGrid Web
System Requirements

Please download the Sharepoint Service 3.0 tools for developing custom Sharepoint applications in VS2005 and later in the following link:

http://www.microsoft.com/downloads/details.aspx?FamilyID=3E1DCCCD-1CCA-433A-BB4D-97B96BF7AB63

© 2001-2009 Copyright Syncfusion Inc. All rights reserved.  |  Privacy Policy  |  Contact  |  Sitemap  |