Google

My Books recommendations

Thursday, October 25, 2007

How to create a simple WebPart in WSS 3.0 for non SharePoint developers

How to create a simple WebPart in WSS 3.0 for non SharePoint developers:

Pre-requisites:


  1. WSS 3.0 server where you can deploy your WebPart
  2. Visual Studio.NET 2005 or Visual Studio.NET 2005 express edition with c# or VB.NET, inherently you will require .NET framework 3.0 install on your machine as part of your VS.NET 2005 installation.
  3. Location of Microsoft.Sharepoint.dll for referencing in your code.
  4. Basic development knowledge of C#


Step by step guide:

1. Open Visual Studio.NET 2005,

2. Click on File > New > Project

3. Click on “Visual C#” as a project type > select “Class Library” as template
4. Type name in name field as “MyFirstWebPart”

5. Click “OK”

5. On your “Solution Explorer” window right click on “References” > “Add reference” > “Browse” > locate your Microsoft.SharePoint.dll and click on OK.

  1. Now click on “Class1.cs” rename the Class1.cs to something like MyWebPart.cs, also change the class name inside the Class1.cs from “public class Class1” to “public class MyWebPart”.
  2. Also, add references to Micorosoft.SharePoint in your class file like this, also, you might see I’ve added additional references to System.Web, and System.Web.UI etc this is if you want to use HTML or Web controls like textboxes or buttons etc. The important or must reference is Microsoft.Sharepoint and Microsoft.SharePoint.WebPartPages which is must for webpart development. Also, you will notice that at the end of the class name declaration I have added a colon “:and WebPart which indicates that the class is a webpart class.

    using System;

using System.Collections.Generic;

using System.Text;

using System.Web;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using Microsoft.SharePoint;

using Microsoft.SharePoint.WebPartPages;

namespace MyFirstWebPart

{

public class MyWebPart: WebPart

{

}

}

  1. In Webpart there are 2 main classes which you need to call to complete a webpart.
    1. “protected override void RenderWebPart(HtmlTextWriter output)” this function will require to render all your controls and HTML on the sharepoint page.
    2. If you want to add user controls or other html or web controls like text boxes or buttons then you will require to add

      protected override void CreateChildControls()”

The complete code will look like this:

namespace MyFirstWebPart

{

public class MyWebPart: WebPart

{

protected override void RenderWebPart(HtmlTextWriter output)

{

base.RenderWebPart(output);

}

protected override void CreateChildControls()

{

base.CreateChildControls();

}

}

}

  1. Now the framework is ready and you can add your code.

    We will be building a small WebPart application which will create a new SharePoint site based on user input.

    The input will be:

    Site URL, Site Name and Site Description, we will use 3 textboxes for these inputs. We will also require one button to submit this user input to our application.

  1. We will be declaring the 3 textboxes and one button at the class level, you can also see that I’ve declared one more variable strMsg as string, this is for displaying the operation messages to the user:

public class MyWebPart: WebPart

{

HtmlInputText TextBox1;

HtmlInputText TextBox2;

HtmlInputText TextBox3;

HtmlButton btnSubmit;

string strMsg;

  1. Now, add this one line inside RenderWebPart()

output.Write(strMsg);

it will look like this, as you can see I h ave commented out the default line, which is not required here:

protected override void RenderWebPart(HtmlTextWriter output)

{

//base.RenderWebPart(output);

output.Write(strMsg);

}

  1. Now, we will create the childcontrols and also will create a server click event for the HTMLButton.

protected override void CreateChildControls()

{

TextBox1 = new HtmlInputText();

TextBox2 = new HtmlInputText();

TextBox3 = new HtmlInputText();

btnSubmit = new HtmlButton();

TextBox1.Value = "";

TextBox2.Value = "";

TextBox3.Value = "";

btnSubmit.InnerText = "Create Site!";

btnSubmit.ServerClick += new EventHandler(btnSubmit_click);

Controls.Add(TextBox1);

Controls.Add(TextBox2);

Controls.Add(TextBox3);

Controls.Add(btnSubmit);

//base.CreateChildControls();

}

  1. The last step for this webpart is to create a server click event for the HTMLButton.

public void btnSubmit_click(object sender, EventArgs e)

{

try

{

SPWeb mySite = SPContext.Current.Web;

SPWebCollection subSites = mySite.Webs;

string currentTemplate = mySite.WebTemplate;

string siteURLBuilder = DateTime.Now.Minute.ToString();

string siteUrl = TextBox1.Value;

string siteTitle = TextBox2.Value;

string siteDescription = TextBox3.Value;

mySite.AllowUnsafeUpdates = true;

subSites.Add(siteUrl, siteTitle, siteDescription, 1033,

currentTemplate, true, false);

string siteText = mySite.Url.ToString();

strMsg = "Site " + siteTitle + " created.The URL for site is : " + siteText + "/" + siteUrl;

}

catch (Exception ex)

{

strMsg = "Catch: " + strMsg + ", EXCEPTION: msg: " + ex.Message + ", source: " + ex.Source + ", innerexception: " + ex.InnerException + ", <br><br>stacktrace:<br>" + ex.StackTrace;

}

}

  1. Now, the coding part is over. Next step is to strong name the webpart assembly. To strong name the webpart assembly you will need to find out sn.exe, if you have VS.NET 2005 installed you can locate it to “<%Installed drive%> Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin” once you found the location of sn.exe, open command prompt from that location and run “sn –k c:\mykey.snk” it will create a key file at root of C drive called “mykey.snk”

14. Now, we need to add an entry of this key file in our project through Assemblyinfo.cs file. The entry will look like this, also check the screenshot for the same.

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

  1. Once the key file entry is done. We are ready to Build the project. Click on build and the project should build fine. Once built, go to the “bin” directory of the project and copy the MyFirstWebPart.dll to Global Assembly Cache (GAC) which is your “<%System dir%>:\WINDOWS\assembly” folder. Once copied into GAC, right click on the dll in GAC and click on properties.

Copy the public key token value and version value and paste it in a note pad.

  1. Now goto your WSS 3.0 server and find Web.config file of the SharePoint site where you want to publish this webpart. In my case my machine itself has WSS 3.0 installed so my web.config file is under “C:\Inetpub\wwwroot\wss\VirtualDirectories\1010” just where 1010 is the virtual directory of my application where I am planning to deploy my webpart.
  2. Once you’ve located your Web.config file, open it and find <SafeControls> tag. Inside this tag you will see many tags like this:

<SafeControl Assembly="Microsoft.Office.Server.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.Office.Server.Search.WebControls" TypeName="*" Safe="True" />

Just copy and paste one of this tag at the end of any of these tags and change the value of Assembly, Version, PublicKeyToken and Namespace to the your assembly’s info which you’ve copied and pasted in a notepad earlier, and it will look something like this.

<SafeControl Assembly="MyFirstWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=296b8720a996b617" Namespace=" MyFirstWebPart " TypeName="*" Safe="True" />

Congrats! You have just registered your first webpart in SharePoint application!

Once registered, now you need to make this webpart available to the site users. For this you need to do following.

Open this page on your sharepoint site:

http://<servername>/sites/<yoursite>/_layouts/NewDwp.aspx

once this page is open, you will see that your first webpart is listed in the list!!

Just select your webpart and click on “Populate Gallery” button which is on top of the page. I always click on “overwrite if file already exists” to be on safe side (when I am redoing this steps for million times…)

Now, your users will get your new webpart under Miscellaneous section, when they will click on “Add new webpart”

It will appear like this:

Add values in the textboxes and click on create site.

You will get this kind of message at the bottom of the webpart (remember strMsg??)

“Site My New Website created.The URL for site is : http://<servername>/sites/<MySite>/MyWebSite”

You can check this site by following the url: it will look something like this:

You have just created your first webpart in SharePoint!!


Friday, September 14, 2007

Document Approval workflow in SharePoint document library

Document Approval workflow in SharePoint document library

Screenshots of Document Approval workflow in SharePoint document library:

1. Upload/Add new document to the document library in Sharepoint.

  1. Initiator uploads desired document (in this case Cardsort.pdf) to the workflow enabled document library.

3. Document status is “In progress” and the Approval status is “Pending”. At this stage normal users will not be able to see the document in the document library.

4. As soon as the document is uploaded in the document library the workflow process kicks in. in this case the workflow process used is the OOB “Approval” workflow process for documents. This workflow process sends emails to the initiator and the Approver/s.

5. The approver will click on his email’s review your task or document link. To review or approve/reject the document.

6. once the document is approved/rejected the status of task assigned to the approver will be changed to “completed”

7. The status of document in the document library will be changed to “approved” if the 1document is approved by the approver.

8. The initiator will get an email notification that the document approval process is complete for his document.

Monday, September 10, 2007

My Personal Blog!

Hi All,

I have also, started my personal blog at following address.

http://vasave.blogspot.com

It will have my personal views, reviews on everything!! except ECM ;-) because, there is only one place where you can find ECM related info: on ECM Lounge....

Any feedback is welcome.

Cheers!
Nilesh

Thursday, September 6, 2007

WSS 3.0 Public Namespaces

The following table lists the public namespaces, identifies their assemblies, and briefly describes namespaces that can be used to customize a deployment.


Name

Assembly

Description

Microsoft.HtmlTrans

Microsoft HtmlTrans Interface (in Microsoft.HtmlTrans.Interface.dll)

Provides an interface for custom conversion applications that deliver HTML versions of documents to users who do not have the required client application or viewer installed on their computers.

Microsoft.SharePoint

Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Provides types and members for working with a top-level site and its subsites or lists.

Microsoft.SharePoint.Administration

Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Provides administrative types and members for managing a Microsoft Windows SharePoint Services deployment.

Microsoft.SharePoint.Administration.Backup

Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Provides types and members for performing backup and restore operations on SharePoint sites.

Microsoft.SharePoint.ApplicationRuntime

Microsoft.SharePoint (in Microsoft.SharePoint.dll)


Microsoft.SharePoint.Deployment

Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Provides types and members for importing and exporting content between Windows SharePoint Services Web sites.

Microsoft.SharePoint.Dsp

Microsoft.SharePoint.Dsp (in Microsoft.SharePoint.Dsp.dll)

Provides the base class for the data retrieval service adapters used in Windows SharePoint Services.

Microsoft.SharePoint.Dsp.OleDb

Microsoft.SharePoint.Dsp.OleDb (in Microsoft.SharePoint.Dsp.OleDb.dll)

Provides the data retrieval service adapter for performing queries against OLE DB data sources.

Microsoft.SharePoint.Dsp.SoapPT

Microsoft.SharePoint.Dsp.SoapPT (in Microsoft.SharePoint.Dsp.SoapPT.dll)

Provides the data retrieval service adapter for performing pass-through queries against arbitrary Web services.

Microsoft.SharePoint.Dsp.Sts

Microsoft.SharePoint.Dsp.Sts (in Microsoft.SharePoint.Dsp.Sts.dll)

Provides the data retrieval service adapter for performing queries against sites, lists, and document libraries in Windows SharePoint Services.

Microsoft.SharePoint.Dsp.XmlUrl

Microsoft.SharePoint.Dsp.XmlUrl (in Microsoft.SharePoint.Dsp.XmlUrl.dll)

Provides the data retrieval service adapter for performing queries against arbitrary XML data sources.

Microsoft.SharePoint.EmailIntegration

Microsoft.SharePoint (in Microsoft.SharePoint.dll)


Microsoft.SharePoint.Help

Microsoft.SharePoint (in Microsoft.SharePoint.dll)


Microsoft.SharePoint.Help.Constants

Microsoft.SharePoint (in Microsoft.SharePoint.dll)


Microsoft.SharePoint.Help.Search

Microsoft.SharePoint (in Microsoft.SharePoint.dll)


Microsoft.SharePoint.Meetings

Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Provides types and members that can be used to customize Meeting Workspace sites.

Microsoft.SharePoint.MobileControls

Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Provides server controls for rendering the mobile forms and view pages used in SharePoint lists.

Microsoft.SharePoint.Navigation

Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Provides types and members for customizing the navigation structures and site maps of SharePoint Web sites.

Microsoft.SharePoint.Search.Administration

Microsoft.SharePoint.Search (in Microsoft.SharePoint.Search.dll)


Microsoft.SharePoint.Search.Query

Microsoft.SharePoint.Search (in Microsoft.SharePoint.Search.dll)


Microsoft.SharePoint.Security

Microsoft SharePoint Security (in Microsoft.SharePoint.Security.dll)

Provides a set of code access permission and attribute classes designed to protect a specific set of resources and operations, such as access to the Windows SharePoint Services object model, the ability to do unsafe saving on HTTP Gets, and enabling point-to-point Web Part connections.

Microsoft.SharePoint.SoapServer

Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Contains classes that implement the Windows SharePoint Services Web Service and Web services for working with Web Part pages and Web Parts. In most cases, the members of these classes are not designed to be called from the server but remotely from client applications.

Microsoft.SharePoint.StsAdmin

Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Provides an interface for creating custom operations to run at the command prompt in STSADM.EXE.

Microsoft.SharePoint.Upgrade

Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Provides types and members for upgrading a Windows SharePoint Services deployment.

Microsoft.SharePoint.Utilities

Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Provides utilities for encoding strings and processing user information.

Microsoft.SharePoint.WebControls

Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Provides server controls that are used on site and list pages in a SharePoint site.

Microsoft.SharePoint.WebPartPages

Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Provides classes, interfaces, and members for creating custom Web Parts and Web Part pages

Microsoft.SharePoint.WebPartPages.Communication

Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Provides a set of interfaces and their supporting classes and members that can be implemented in the class of a custom Web Part to support creating connections with other Web Parts.

Microsoft.SharePoint.Workflow

Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Provides types and members for associating, initiating, and managing workflow templates and instances.

Microsoft.SharePoint.WorkflowActions

microsoft.sharepoint.WorkflowActions (in microsoft.sharepoint.WorkflowActions.dll)

Provides types that represent workflow activities. These activities can be assembled into workflow activities.

Wednesday, August 22, 2007

SharePoint Security Roles (Administration) - Analysis

SharePoint Security Roles - An Analysis 2

Admin Level

SharePoint Group

Does role exist by default?

Can do this

Cannot do this

Server or server farm level

Farm Administrators

Yes

Perform administrative tasks in Central Administration.

Administer individual sites or site content unless they take ownership.

Take ownership of any content site.

Administer My Sites.


Access the Shared Services Administration site.


Create or delete SharePoint Web applications.


Update the accounts or passwords for existing Web applications and NT services.


Deploy solutions that require updating the global assembly cache (GAC).


Restore from backup.

Server or server farm level

Administrators

Yes. Windows group that exists by default; not a SharePoint group.

Install products.

Administer individual sites or site content.

Create new Web applications and new Internet Information Services (IIS) Web sites.

Administer My Sites.

Start services.

Administer databases

Deploy Web Parts and new features to the global assembly cache.


Perform all farm-level tasks in Central Administration (provided that the Central Administration site is located on the local computer).


Run the Stsadm command-line tool.




Shared services level

SSO Administrators

No. Need to enable the SSO service for administration to occur, and then the SharePoint group needs to be created.

Configure and manage the SSO service in Office SharePoint Server 2007, including managing the encryption key.

Administer individual sites or site content.

Create, modify, or delete enterprise application definitions within Office SharePoint Server 2007.

Administer My Sites.

Redeem SSO tickets. In scenarios in which credentials pass through an intermediary service (such as Microsoft BizTalk Server) before reaching the enterprise application definition, this group is used to give intermediary services permissions to redeem SSO tickets.

Use the Shared Services Administration Web site.


Use Central Administration.

Shared services level

Enterprise application definition administrators

No. Need to enable the SSO service for administration to occur. Must be global group account or individual user account. This account cannot be a domain local group or a distribution list.

Create, manage, and delete enterprise application definitions.

Administer individual sites or content.

Update enterprise application accounts and credentials.

Administer My Sites.


Access the Shared Services Administration Web site.


Access Central Administration.

Shared services level

Site collection administrator for the Shared Services Administration site

Yes. The account that created the SSP is automatically the site collection administrator for the Shared Services Administration site.

Use the Shared Services Administration Web site with the Full Control permission level.

Administer individual sites or site content.

Configure usage reporting.

Administer My Sites.

Add users to the default Readers group for sites containing My Sites and profiles.


Create personal sites.


Manage sites and user profiles.


Configure permissions for specific services or delegate administration of shared services to other users.


Shared services level

Shared Services administrator

No. The Shared Services site collection administrator must add a user to the Shared Services Administration site and then assign permissions to the appropriate shared services.

View Shared Services Administration site.

Administer individual sites or site content.

Configure usage reporting.

Add users to the default Readers group for sites containing My Sites and profiles.

Create personal sites.

Manage sites and user profiles.

Configure permissions for specific services or delegate shared services administration to other users.

Shared services level

Search Administrators

No. The Shared Services site collection administrator must add a user to the Shared Services Administration site.

Create and manage content sources and crawl schedules.

Access the Central Administration site.

Manage file types.

Create and manage the default content access account.

Create server name mappings.

Activate or deactivate search-based alerts.

Create and manage search scopes.

Specify authoritative Web pages.

Manage metadata properties.

Shared services level

Profile Services administrator

No. The Shared Services site collection administrator adds a user by clicking the Personalization services permissions link.

Configure personalization services permissions (only if given the Manage Permissions permission).

Access the Central Administration site.

Import people properties from directories and the Business Data Catalog.

Manage audiences (unless specifically granted that permission by the Shared Services site collection administrator.)

Customize and configure My Sites settings and permissions.


Configure and manage user profiles.


Configure profile services policies.


Edit and view all the information to the user public profile.


Shared services level

Audiences Services administrator

No. The Shared Services site collection administrator adds a user by clicking the Personalization services permissions link.

Configure the Audiences service.

Access any other shared services except Excel Services and Search.

Manage, create, and compile audiences.

Access the Central Administration page.

View audiences membership.

Manage user profiles (unless specifically granted that permission by the Shared Services site collection administrator).

Shared services level

Business Data Catalog service administrator

No. The Shared Services site collection administrator adds a user on the Manage permissions page for the Business Data Catalog.

Register applications in the Business Data Catalog.

Access any other shared services except Excel Services and Search.

Configure business data search.

Access the Central Administration site.

Customize business data lists, Web Parts, and sites.


Configure business data profiles.


Configure business data connections.


Shared services level

Excel Services administrator

No. The Shared Services site collection administrator must add a user to the Shared Services Administration site.

Add trusted file locations.

Access the Central Administration site.

Add trusted data providers.

Start and manage the SSO service.

Add trusted data connection libraries.

Start or stop Excel Calculation Services or other services.

Add user-defined function assemblies.

Run Stsadm command-line administrative operations.

Modify Excel Services settings.


Access other administration pages (for example, the Business Data Catalog Applications page).


Shared services level

Usage reporting administrator

No. This group is created by the Shared Services administrator.

Configure usage reporting service by using the Shared Services Administration site.

Access any other shared services.

View and edit site usage and summary pages.

Access the Central Administration site.



- Configure search query logging.




Site Level

Site collection administrator

Yes

Perform all administration tasks for sites within the site collection.

Access the Central Administration site.

Site Level

Owners

Yes

Perform administration for the site only, not the entire site collection.

Access the Central Administration site.

Perform administrative tasks for documents, lists, and libraries.

Access the Shared Services Administration site.


Perform site collection administration tasks, such as restoring items from the second-stage Recycle Bin and managing the site hierarchy.