The ClassResourcePath for custom webparts in MOSS 2007

понедельник, 23 апреля 2007 г.

At Macaw we've been using standard project templates for most of our development projects for years. In the project template for custom webparts for SharePoint 2003 we've had a basewebpart. All custom webparts for SharePoint 2003 inherit from the basewebpart. On of the things the basewebpart takes care of is determining the ClassResourcePath.

Custom web parts can be deployed to the wwwroot/bin directory or to the global assembly cache (GAC). The deployment location also affects the location where resources (for instance usercontrols and images) that are required by the web part are stored. For GAC deployments, the directory is mapped to /_wpresources/[assembly_name]. For bin directory deployments, the directory is mapped to /wpresources/[assembly_name].

In order to determine the resource path at runtime you use the ClassResourcePath of Microsoft.SharePoint.WebPartPages.WebPart.


For SharePoint 2007 Microsoft recommends inheriting custom webparts from System.Web.UI.WebControls.WebParts.WebPart. Unfortunately this class doesn't contain an equivelant of the ClassResourcePath. However if you're building a basewebpart that will be used by a lot of custom web parts you do want to be able to determine the path where the resources are stored at runtime, since you don't beforehand know whether a web part will be deployed in the bin or in the GAC.

In order to be able to do this I've used SPWebPartManager.GetClassResourcePath. You can use this class, that is inherited from Microsoft.SharePoint.WebPartPages and at the same time inherit the web part itself from System.Web.UI.WebControls.WebParts.WebPart in order to comply with Microsoft recommendations.

The code getting the resource path will look like this:

SPWeb currentWeb = SPControl.GetContextWeb(Context);
Type currentType = BaseWebPart.GetType();
string classResourcePath = SPWebPartManager.GetClassResourcePath(currentWeb, currentType);

Source: http://www.sharepointblogs.com/mirjam/archive/2007/01/17/17995.aspx

My comments:

Don't forget to include namespaces:

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

Appling this to loading user control for the web part installed in GAC got an error:

'http://tutelo/_wpresources/NewsView.ascx' is not a valid virtual path.

Strange thing that '/_wpresources/NewsView.ascx' works just fine. Seems that we'll need relative URL part for the resourse to load.

The bad news is that adding user contol as resources is a bad idea. They should be distributed over the load balanced SharePoint servers, so there will be no vrirtual path. That's why GetClassResourcePath() returns full path, not virtual.

For now I decided to put user controls in _layout. _Layout can be configured using Solutions upon deployment. Let's see where I'll come with this solution...

WSS 3.0 Tools: VS 2005 Extensions - why is there no 64-bit version for WinXP/WIndows Server 2003 64-bit?!

Q: Any chance this will be released to work on an XP box?

A: VSeWSS only runs on Windows Server 2003 with VS and WSS locally. Please see below topic for installation.

Preparing the development environment

http://blogs.msdn.com/spdev/archive/2007/01/26/preparing-the-development-environment.aspx

Q: How are localized solutions/resources/language packs handled?

I dug down into the manifest.xml file for the solution, added a element and it was removed from the manifest.xml file upon deployment. Is localization something we need to do manually after the solutions is completed?

A: WSeWSS removes all files under bin//solution before creating *.wsp file in deployment phase, the solution directory is just temporary directory for creating *.wsp file. That’s why your changes are gone after deployment.

If you would like to change contents of *.wsp file, you need to do follow steps.

1. Finish development on Visual Studio

2. Edit under bin//solution directory contents

3. Create *.wsp from the solution directory

4. Deploy & Activate the *.wsp via stsadm.exe

Q: Is there any hope of a 64-bit version being released?

A: Unfortunately we have no plan to release 64-bit version of VSeWSS.

Q: If not, are there any resoueces for creating web parts without the templates?

A: This article can help you.

Walkthrough: Creating a Basic Web Part


http://msdn2.microsoft.com/en-us/library/ms415817.aspx


Source: http://blogs.msdn.com/spdev/archive/2007/03/16/vsewss-version-1-0-has-been-released.aspx

WebParts deployment - Solutions for SharePoint 2007

пятница, 20 апреля 2007 г.

I found a good article on the CodeGuru explaining steps to deploy solutions in MOSS:

http://www.developer.com/net/net/article.php/3672646

Say the truth, I used the save principle in the SharePoint 2003, but installation was straight forward and could not be controled by system administrator from the administrative pages.

Seems, SharePoint 2007 solved this problem - let's see.

SharePoint 2007 Custom Properties

I had WebParts developed for SharePoint 2003.

They inherited from Microsoft.SharePoint.WebPartPages.WebPart class.
I followed recommendations and update them to System.Web.UI.WebControls.WebParts.WebPart. I got the error:

error CS0115: 'IDSKWPHoroscope.Horoscope.GetToolParts()': no suitable method found to override

Googling the problem I found this article:

http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=1453072&SiteID=17

It didn't help however. My goal was to switch to the new .NET Framework 2.0 classes and not continue using Microsoft.SharePoint.WebPartPages.WebPart class.

Solution came from Share Point documentation. New WebPart class has method:

public virtual EditorPartCollection CreateEditorParts()
that replaces the old one:

public virtual ToolPart[] GetToolParts()
Now it uses a collection of EditorParts.

The toolparts should inherit from

System.Web.UI.WebControls.WebParts.EditorPart


istead of

Microsoft.SharePoint.WebPartPages.ToolPart

Some over properties changed in the EditorPart class in comparison with ToolPart class (like AcceptChanges() now returns bool and there is no CancelChanges() ).

Small twicks solve problems.

Adding Web User Control To A Class Library In VS.NET 2005

If you’ve started on module development with DotNetNuke 4.0 and above in Visual Studio.NET 2005, you might run into a problem with trying to add a Web User Control (*.ascx file) to a class library.

The fix is similar to what you had to do with Visual Studio.NET 2003.

For C#, follow these steps.

  1. Close VS.NET 2005.
  2. Open the directory C:\Program Files\Microsoft Visual Studio 8\Web\WebNewFileItems\CSharp (assuming a default installation of VS.NET).
  3. Open the CSharpItems.vsdir file in Notepad. Select the text and copy it to the clipboard.
  4. Now open up the file C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjectItems\CSharpItems.vsdir and paste the contents of the clipboard underneath the existing text.
  5. Now copy the contents of C:\Program Files\Microsoft Visual Studio 8\Web\WebNewFileItems\CSharp (excluding CSharpItems.vsdir) into the folder C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjectItems.

Now “Web User Control” should be an option when you select Add | New Item.

Source:

http://haacked.com/archive/2006/02/07/AddingWebUserControlToAClassLibraryInVS.NET2005.aspx


Add it works!

Let's start

Ok, let's start this crazy blog about crazy .NET