Showing posts with label Sharepoint. Show all posts
Showing posts with label Sharepoint. Show all posts

Thursday, November 12, 2009

WebPart Creation & Deployment

Custom Web Part Creation and Deployment

Creating Web User Control in VS2005 or VS2008.
Step 1: Create new project (Web application Project)
Note: Do not use new Web Site when creating project.
Step 2: Name the Project with good name. Since this becomes our DLL.
Step 3: Create Web User Control, with complete UI and Logic.
Step 4: Build the project. Which will create a DLL.

Create Web Part Project Library:
This project is our Web part Library. Usually we will create only one Library project for all the web parts we develop.
Step 1: Open new dev VS2005. Create New Library Project.
Step 2: Name the project with Good name. (This becomes Dll)
Step 3: Add a reference system.web to the project. This contains all the related name space for web part to work in share point.
Step 4: Add a Class. Name it. This becomes the WebPart.
Step 5: Import below name space.
using System.Web.UI.WebControls.WebParts;
Step 6: Inherit WebPart Class.

namespace BasicWebParts
{
public class HelloWorld:WebPart
{

}
}
Step 6: Override Create control method .And modify the code to reflect the user control file name.



Example class code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI;

namespace BasicWebParts
{
public class UserControlWebPart:WebPart
{
Control cntrl;
protected override void CreateChildControls()
{
this.cntrl = this.Page.LoadControl(@"~/usercontrols/ucDisplay.ascx");
this.Controls.Add(this.cntrl);
}
}
}

Change only the ucDisplay.ascx only to your user control.

Step 7: (Important)
Add the below line to AssemblyInfo file located under Properties folder .
[assembly: System.Security.AllowPartiallyTrustedCallers]
Better Add it at the end.

Information: This related to security issue while inporting the Webpart by sharepoint.

Step 8: Creating snk file.
1.Open Application Properties as shown below Image.



2. Click on signing  Choose Strong name key  as shown in below.



3. Enter Project Name as snk file name and uncheck the Protect my key file with password.
4. Click ok. And save the changes. snk file got created.

Step 9: Build the Project. Get the Dll.
Step 10: Extract public Key token.
Open visual studio 2005 command prompt.
Enter sn –T “Path of the dll”
Example: sn -T “C:\Project1\bin\debug\Test.dll”
Note the Public Key Token: it will be like example “fa29fd297c3b296b”
Step 11:
Add Safe Control Tag in Web.config of the site. To find web.config go to IIS server virtual directory and explore the same.
By Default Location is like : C:\inetpub\wwwroot\wss\virtualdirectories\siteport
Open Web.config . Copy paste one safe control tag from their and modify the Assembly PublicKey token, Namespace.
Example:


Step 12: Deploy dlls and supporting files.
1. Deploying User Control s
2. Create a folder “usercontrol s” in the site root .
Assume 1001 is the site port we created. Create the directory like below
C:\inetpub\wwwroot\wss\virtualdirectories\1001\usercontrols.
Step 13: Place ASCX controls to this folder.
Step 14: Place WebpartDlls, WebUserControl dlls created from above steps into bin folder.

Adding web part to the site:

Step 1: Open site - Click Site Actions - Site Settings - Webparts  Webpart gallery will open
Step 2: Click New . New ly created webpart are displayed. Check the web part to add into current site.
Step 3: Add web part from web part pane to any webpart page.

Note:
rest of the activities whatever functionality/design we can change as it Usercontrols update to reference folder.

SharePoint Architecture

Server Architecture:


1. The SPFarm object is the highest object within the Windows SharePoint Services object model hierarchy. The Servers property gets a collection representing all the servers in the deployment, and the Services property gets a collection representing all the services.
2. Each SPServer object represents a physical server computer. The ServiceInstances property provides access to the set of individual service instances that run on the individual computer.
3. Each SPService object represents a logical service or application installed in the server farm. A service object provides access to server farm-wide settings of the load-balanced service that a respective service instance implements. Derived types of the SPService class include, for example, objects for Windows services, such as the timer service, search, Microsoft SQL Server, the database service, etc. and also objects for Web services, such as Windows SharePoint Services or services in the Microsoft Office system.
4. An SPWebService object provides access to configuration settings for a specific logical service or application. The WebApplications property gets the collection of Web applications that run the service.
5. An SPDatabaseServiceInstance object represents a single instance of a database service running on the server computer. The SPDatabaseServiceInstance class derives from the SPServiceInstance class and thus inherits the Service property, which provides access to the service or application that the instance implements. The Databases property gets the collection of content databases used in the service.
6. Each SPWebApplication object represents a load-balanced Web application based in Internet Information Services (IIS). The SPWebApplication object provides access to credentials and other server farm wide application settings. The Sites property gets the collection of site collections within the Web application, and the ContentDatabases property collection of content databases used in the Web application. The SPWebApplication class replaces the obsolete SPVirtualServer class; but it can still be helpful to think of a SPWebApplication object as a virtual server; that is, a set of one or more physical servers that appear as a single server to users.
7. An SPContentDatabase object inherits from the SPDatabase class and represents a database that contains user data for a SharePoint Web application. The Sites property gets the collection of site collections for which the content database stores data, and the WebApplication property gets the parent Web application.
8. An SPSiteCollection object represents the collection of site collections within the Web application. The Item property or indexer gets a specified site collection from the collection, and the Add method creates a site collection within the collection.
Site Architecture



1. Each SPSiteobject, despite its singular name, represents a set of logically related SPWeb objects (see below). Such a set is commonly called a "site collection," but SPSite is not a standard Microsoft .NET collection class, in contrast to SPWebCollection. Rather, it has members that can be used to manage the site collection. The AllWebs property provides access to the SPWebCollection object that represents the collection of all Web sites within the site collection, including the top-level site. The Microsoft.SharePoint.SPSite.OpenWebmethod of the SPSite class returns a specific Web site.
2. Each site collection includes any number of SPWeb objects, and each object has members that can be used to manage a site, including its template and theme, as well as to access files and folders on the site. The Webs property returns an SPWebCollection object that represents all the subsites of a specified site, and the Lists property returns an SPListCollection object that represents all the lists in the site.
3. Each SPList object has members that are used to manage the list or access items in the list. The GetItems method can be used to perform queries that return specific items. The Fields property returns an SPFieldCollection object that represents all the fields, or columns, in the list, and the Items property returns an SPListItemCollection object that represents all the items, or rows, in the list.
4. Each SPField object has members that contain settings for the field.
5. Each SPListItem object represents a single row in the list.

Copyright © 2009 Angel