The thing to do is use .Net 2.0 web parts and override CreateEditorParts or implement IWebEditable on generic controls that are not web parts.

A good link on how to do that (once you know what to look for, duh!) is How to get EditorParts working in your WebParts.

Another link that summarises different solutions for several issues with web parts is WSS 3.0 webparts development. A quote that is relevant to this blog entry:

Toolpanes can be customized in a number of ways. A web part by itself can declare custom toolparts which show up in the toolpane by overriding the GetToolParts method (WSS WebPart) or CreateEditorParts (ASP.NET WebPart).

A developer can also customize the toolpane generically by supporting the ICustomizeToolpane interface (which allows you to redefine the structure of the toolpane UI) or supporting IAddToGallery (which allows you to add new gallery "tabs").


I am still working on clarifying that out as the documentation from MSDN is almost non existent on the subject. It appears that using ICustomizeToolPane is only supported for Sharepoint web parts and not for ASP.Net web parts. I yet know of no other way of changing the toolpane except by using some javascript from the web part editor (which would suck) and it might not even be possible.

Update: The rest of this post is not longer relevant. I believe it is the way it was done in the old Sharepoint days, when Sharepoint web parts were not based on ASP.Net 2.0.

Click to show anyway

This entry will be sort of unorganised, as I am slowly crawling to the jungle of options and bad documentation for Sharepoint. I will structure it as a list of points that I pass through and the solution for each problem. Hopefully, you will find something useful in it.

First of all, you cannot run Sharepoint on XP. Don't event try it. You need at least a Windows 2003 machine with the free Windows Sharepoint Services (acronym WSS) or with the commercial Microsoft Office Sharepoint Server (acronym MOSS) installed. In order to access the site, you will have to access the http://SharepointComputer URL.

Section: publishing a web part to the Sharepoint site running on WSS.
  • A web part project is a class library with associated libraries for it. First step is publication, which means copying the library files into the sharepoint site bin folder.
    Solution:
    1. find the physical location for the Sharepoint site onto the Sharepoint computer(usually wwwroot\wss\VirtualDirectories\80)
    2. copy the library files in the bin subfolder
  • Second step is loading the web parts into the Sharepoint gallery.
    Solution:
    1. open the http://SharepointComputer url
    2. open the Site Actions top-right menu and go to Site Settings
    3. open the Galleries - Web Parts link
    4. select the New option from the top toolbar
    5. the webparts in the library should appear in the list. check the checkbox next to them
    6. click Populate Gallery. now the web parts should be available in any page
  • Last step is adding the web parts to a page.
    Solution:
    1. go to any page that you can edit
    2. go to Site Actions and select Edit Page
    3. click the appropriate Add a Web Part header
    4. check the checkbox next to the web parts you want added, then click OK


Section: Troubleshooting the published web parts
  • If you have an error, you probably have a generic error page that says nothing of relevance.
    Solution:
    1. go to the physical location of the Sharepoint site
    2. edit the web.config file and set customErrors to mode="Off"
    3. refresh the Sharepoint site page in the browser
  • Now the error is much clearer and you see permissions errors that show Access Denied.
    Solution:
    1. go to the physical location of the Sharepoint site
    2. edit the Properties of the library files that you copied in the bin folder and set access for the asp.net user or (if you are lazy) for Everyone to read the site
  • Now the error you see other permissions errors of which you understand nothing, mostly linked to OnPrerender or Render methods.
    Solution:
    1. go to the physical location of the Sharepoint site
    2. edit the web.config file and (if you are lazy) set trust to level="Full" (capital F) or try to create your own security policy (complicated)
    3. refresh the Sharepoint site page in the browser
  • Oh, joy, the ugly error page with lots of information has vanished, leaving instead a nice error page saying nothing useful except File Not Found.
    Solution:
    1. go to the physical location of the Sharepoint site
    2. edit the web.config file and set compilation to debug="true" and SafeMode to CallStack="true"
    3. refresh the Sharepoint site page in the browser
  • Weird and unexplained errors occur.Solution:
    1. on the Sharepoint computer go to Administrative Tools and select Sharepoint 3.0 Central Administration
    2. that should open a site that is used to configure the Sharepoint site
    3. alternatively you can try the same Sharepoint URL in the browser, but using the port that was assigned to the configuration site (you can get the port from the name of the folder in wwwroot: wwwroot\wss\VirtualDirectories\[port that is not 80]
    4. go to the Operations section and select Diagnostic Logging
    5. In the Trace Log section you should see a Path, copy it to the clipboard
    6. Open the said path in Start/Run and it should open the Logs folder
    7. Open the latest log file (might need to press Ctrl-R to refresh the folder or to close the log file if already open and reopen it) and look for any cause for the errors


To be continued...

Recently I have been working on this Sharepoint project. I took it more out of curiosity as I didn't know anything about this piece of software. Now I know a lot more, like how hellish it is to code against it :) But it is also not a bad idea.

In case you don't know (as I didn't) Sharepoint is something like an ASP.Net site designed to work within a company, as an internal tool, allowing a lot of customizations and security from the web interface, with no code required. The desired end result is something looking like the IGoogle or Yahoo home pages, with web parts that can be configured, moved around, minimized, closed, made to interact one with another. Sharepoint Services is in itself a free software, but it only works on a Windows 2003 server or higher, so it sucks that way. Also, there is no real Sharepoint support for Visual Studio and most of the tutorials you find online are either too specific (blogs and such) or too vague (Microsoft style).

Also, there is a lot of confusion regarding the use of the interfaces in the Sharepoint dll, most of which have been obsoleted when the web part engine from .Net 2.0 was introduced.

Ok, short list of steps on how to start making a Sharepoint project in Visual Studio, assuming you code in Windows XP:
  1. Install Windows Server 2003 on another machine (virtual or not)
  2. Download and install Sharepoint Services 3.0 SP1 on it
  3. Get the Microsoft.Sharepoint.dll file and copy it on your XP machine somewhere
  4. Download and install the Sharepoint SmartTemplates for Visual Studio
  5. Update the WSPBuilder application and some batch files in the template files
  6. Start Visual Studio and create new project from installed templates
  7. Add a reference to the Microsoft.Sharepoint.dll library
  8. Code!
.

Now for the long list.
In order to install Sharepoint Services 3.0 SP1 you need to also install .Net 3.5 SP1. Actually it is a good idea to install this as well as the Visual Studio 2008 SP1 before you do anything (Sharepointy or not). Here is a link.

The Sharepoint SmartTemplates actually create a folder structure that is then used by the WSPBuilder utility to create the WSP file that installs a web part in Sharepoint. You can either import it in the site (upload) or use the setup that is provided with the templates. The problems I met when using it are linked primarily with the version of WSPBuilder that is included in the templates I've downloaded (version 0.2).
So first locate the installed template files: you can usually find them in My Documents/Visual Studio 2008/Templates/Project Templates/ as two zip files. First step is to download the latest WSPBuilder and replace it in the archives. The next step is to change the WSP/createwsp.bat file like this:
@ECHO OFF
DEL .\$safeprojectname$.wsp
ECHO Copying DLL ...
XCOPY /Y ..\BIN\$safeprojectname$.dll .\80\BIN\
ECHO Copying ASCX files ...
XCOPY /Y ..\*.ascx .\12\TEMPLATE\CONTROLTEMPLATES\$safeprojectname$\
ECHO Building WSP ...
..\WSPBuilder\WSPBuilder.exe -WSPName $safeprojectname$.wsp -BuildCAS false -SolutionID $guid2$ -DLLReferencePath "[the folder path where you copied Microsoft.Sharepoint.dll]" -TraceLevel Verbose
ECHO Copying WSP file ...
XCOPY /Y .\$safeprojectname$.wsp ..\SETUP\

The bold parts you must add to the file. The delete because otherwise you might be able to compile the project using the old WSP file if the WSPBuilder run fails. The others is in order to be able to compile the WSP using the sharepoint library and see any errors that might occur.
Alternatively, you can change the WSPBuilder/WSPBuilder.exe.config file with the DLLReferencePath and TraceLevel options.
Ok, now repack the folders into the archives and copy them back.

Now, after you build the project, you will have a Setup folder in the bin folder. That you must copy to the Windows 2003 computer and run. It will install the web part(s) in the project. In order to add more webparts to the project and make them compile in the setup project you need to alter the WSP\12\TEMPLATE\FEATURES\SmartPartTemplate\manifest.xml file and describe the files you add to the project.

After you run the setup project, you have to open the Sharepoint site and go to Site Settings -> Site collection features and activate the web part. Only then you can actually add it to a page.

Sounds complicated? Well, read more :)

Make sure that when you have finished with a web part you DO NOT DELETE THE SETUP PROJECT, but run it to remove the web part first! In order to remove an install web part from a Sharepoint site you must delve into the hell of command line utilities! Well, it's natural to me, but I am an old guy! ;)

Just supposing that you have done the undoable and you managed to delete a setup project with the part still installed, you must use the stsadm tool.
First find it on the Windows 2003 computer (with Find Files) then add the containing folder to the path. Then run cmd in the Start/Run menu and use the following commands:
stsadm -o enumsolutions
will enumerate the installed solutions. Remember the name of the solutions you want to remove.
stsadm -o retractsolution -name "[name of solution]" -immediate
will retract the web part project and allow you to delete it.
stsadm -o deletesolution -name "[name of solution]" -override
retracting doesn't always work, so the override option will force a delete.

Sometimes you manage to change the GUID of the project and you get an error like A solution with the same name "SomeName.wsp" or id "Some GUID" already exists in the solution store.. You delete it, but you still have this error. Try to install the solution with the setup project. Wait for the error, exit the setup project. Use stsadm -enumsolutions to see what the GUID of the project is, copy it, replace the SolutionId GUID in the setup.exe.config file with this one. The setup should then work.

This is about it. I've wasted a few hours to learn all of this. I know it's not terribly organized, but writing something is better than sharing nothing.