Wednesday, January 24, 2007

Beginner's Sharepoint Custom webpart using Web Control Library

  1. VS 2005 -> File -> New Project ->Visual C# Projects -> Web Control Library.
  2. Name it as 'Simple Webpart' and Specify the project location.
  3. Add reference to Microsoft.Sharepoint.dll and System.XML

    (Solution explorer -> References -> right click -> Add Reference -> .NET -> search and select the name spaces above.)
  4. Add the following to the using section:

    using System.Security;
    using Microsoft.SharePoint.WebPartPages;
    using System.Xml.Serialization;
  5. Edit the AsseblyInfo.cs to preserve a fixed version each time you build.
    Replace the
    [assembly: AssemblyVersion("1.0.*")]so that it reads[assembly: AssemblyVersion("")]

  6. Add the following statement in the AsseblyInfo.cs at the end.

    [assembly: System.Security.AllowPartiallyTrustedCallers]
  7. Chnage the name space so that we can have any number of webparts under a single namespace.

    namespace SimpleWebPart
    namespace MyWebParts
  8. Change the class declaration to inherit from the webpart class.
    public class SimpleWebPart : WebControl
    public class SimpleWebPart : WebPart
  9. Replace
    protected override void Render(HtmlTextWriter output)
    protected override void RenderWebPart(HtmlTextWriter output)
  10. Add the code needed in the webpart, add necessary child controls you needed.
    Replace the code in the Render webpart method with
  11. Strong name the assembly
  12. Copy the dll to the 'bin' directory of the application.
    C:\Intepub\wwwroot\wss\virtual directories\port number
  13. GAC the assembly:
    Drag and drop the dll to 'C\Windows\Assembly
  14. Increase the Default Trust Level and Add a SafeControl Entry for your Web Part

    Open the web.config file in the Web application root(C:\inetpub\wwwroot\wss\virtual deirectories\port\web.config) -> In the level attribute of the trust section, change WSS_Minimal to WSS_Medium.
  15. Add the assembly to the safe controls.
    Within the web.config file opened above, locate the
    <safe controls >
    section and add the following:

    <SafeControl Assembly="SimpleWebPart, Version=, Culture=neutral, PublicKeyToken=PublicKeyToken" Namespace="MyWebParts" TypeName="SimpleWebPart" Safe="True"/>

  16. In the above line, MyWebparts is a namespace.
    SimpleWebPart is an assembly name.
    C:\Windows\Assembly\SimpleWebPart -> right click -> properties.
    you can find the key value from the following command.
    Open the visual studio command prompt and type:
    sn.exe -T C:\inetpub\wwwroot\wss\VirtualDirectories\PortNumber\bin\SimpleWebPart.dll
  17. Open a notepad and copy paste the following lines;
    <?xml version="1.0"?>
    <WebPart xmlns="; <Assembly>SimpleWebPart, Version=, Culture=Neutral, PublicKeyToken=PublicKeyToken</Assembly> <TypeName>MyWebParts.SimpleWebPart</TypeName>
    <Title>My Simple Web Part</Title>
    <Description>A simple Web Part</Description>

    Save the file as 'SimpleWebPart.dwp' and save at the bin folder, where the dll is copied
  18. Site Actions -> Site settings -> galeeries -> Webparts -> upload -> browse to the above .dwp file.
  19. Site Actions -> Edit Page -> Add Webpart -> drag and drop the webpart on the page.

Tuesday, January 23, 2007

This product can only be installed if Windows SharePoint Services 3.0 has been installed first


While trying to install VS extensions for sharepoint 2007/wss 3.0 on the machine that does not has sharepoint installed, get the following error.


  1. open the regedit and create the following keys and the string value

    Windows Registry Editor Version 5.00
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0]
  2. If you are new to regester edit, simply copy the above text into a new notepad, save the notepad as 'temp.reg' -> double click on the temp.reg -> accept the warning.

Friday, January 19, 2007

The Path specified cannot be used at this time,Internet Information Services when sharepoint(MOSS) deployed.

Problem Definition:

When you invoke the IIS Manager, it will take longer time than usual to open. And when it opens, opens with an Empty console. No Application pools, No Websites are found.
After that, when you try to connect the server remotely, error "The Path specified cannot be used at this time" was thrown.


IIS Reset will solve the problem always. But there some other work arounds I heard from my colleague. Here they are:
  1. Restart the Windows SharePoint Services Timer service.
  2. Command Prompt -> change directory to .NET Framework folder
    aspnet_regiis.exe -i