Skip to content

SCHEMA.XML — Continuation Character?

At the client I’m at we’re doing some customization of the SCHEMA.XML files for the list templates.  Basically, we’re adding some web parts into the pages since our header, footer, and navigation is driven from web parts.  I was over with one of the developers and noticed he was looking at the SCHEMA.XML as a text file.  When I asked why he showed me, VS.2003 wasn’t able to show a XML view.

So I fired up my copy of Stylus Studio (which tells me why something isn’t valid XML in addition to just blowing up.)… I found that there were a few lines in the schema.xml which look like they were “continued.”  They had an exclamation point and a carriage return at the 990th position on a line.  I’ve checked through the other SCHEMA.XML files and can’t find the character … so I don’t know how it got there, but if you run into a schema.xml that won’t load, perhaps some utility has decided to add a line continuation character…

SharePoint Web Part Administrator (SPWPADM)

STSADM in addition to being a swiss army knife of useful little functions is also one of the most frequently used tools in SharePoint deployments.  Being the gatekeeper to easy web part deployment has it’s advantages.  However, there are limitations that it has and features that it hasn’t implemented.  That’s where one of my latest projects comes in.

First, STSADM is very dependent upon access to the SharePoint content database.  If you don’t have enough access the tool doesn’t work.  This can be worked around, however, in many environments it represents a barrier to easily using STSADM.

Second, although STSADM allows you to add and remove web parts as trusted assemblies on the server — and deploy default property sets (read as “DWP files“) it does not allow you to add or remove web parts from a web part page from the command line.

However, I’ve been working on a tool the “SharePoint Web Part Administrator” (SPWPADM) that solves both of these two limitations.  First, it is entirely based on the web service interface to SharePoint.  You can run it from your desk, from the server, or anywhere that you can access the SharePoint built-in web services.  Second, it’s exclusive function is to manage web parts on web part pages.

It allows you to enumerate the web parts on a page, add new web parts to a page, delete web parts from a page, export web parts from a page, and even to delete closed web parts on a page.  Of all of those, perhaps only the last function needs any explanation…

When people “delete” a web part from SharePoint they’re often times just closing it — suppressing the display.  The code is actually still running it’s just that people don’t see the results on the page.  That’s really not all that great if you’re doing extensive computations to come up with content that will never be displayed.  However, the only way to delete a web part is to enter design mode to delete it.  The result is most people close web parts without realizing the impact on their server.

The SPWPADM tool will hunt down these closed web parts and actually delete them for you so they’re no longer running.

So, there are two questions you might ask… 1) “Why did you write the tool?” — The primary reason is because I’m working on an article for on how to replace the edit control (ListFormWebPart) for a list.  To do that you have to add a new web part to the list pages and remove the existing web part.  It’s possible to do but certainly kludgy.  So I thought the tool would be a nice thing to offer folks as a trial with the article.  It’s turned into slightly more than that as I realized other purposes for it, but at heart it’s designed to facilitate management of a web part page from the command line.

2) “So what is it useful for?” — Thus far I’ve used it for two things… First, deleting closed web parts.  You would be amazed at how many of them there are in a typical SharePoint implementation.  Second, helping to configure site definitions while building/testing them.  When I build a site definition I typically have a page that is composed entirely of web part zones.  I don’t have a header, I don’t have a footer, nor menus, nor other parts of the page, those functions are represented by web part zones and by web parts.  (Yes, I know this is slightly wasteful from a configuration storage perspective — it does, however, make staying supported while making changes much easier.)  So I typically make 20 copies of my default page so I can drop in other content as needed.  That means adding half a dozen web parts to each page (header, footer, search, global navigation, site navigation, etc.)  So I make a batch file that calls the add web part command for each web part.  I nest this in a batch file in one that calls it once for each page.  It takes a while but eventually the controls are all placed on every page.

So why am I bringing this up?  Well, two reasons, I’m ready to let a few people try it out (send me an email and I’ll send you a copy of it along with a license.)  Second, I got someone asking about how to lock web parts in place for 50 or so sales guys on a discussion list I watch.  It occurred to me it’s possible to put this in a script that runs every night and deletes and then readds the web parts — the net effect of which is forcing them to be on a page since changes, or removal will be removed each day.  Not pretty but an idea that would be easy and effective.

So if you’re interested, drop me a line and I’ll get you a beta/trial copy.

CorasWorks: Growing with the deployment

I typically don’t make a big deal out of the software I use on a daily basis because I figure that people have their own unique needs and we all get bludgeoned nearly to death by constant bombardment with new tools, techniques, and processes that are going to save the world.
However, I’ve been spending a fair amount of time with CorasWorks lately and there were a few observations I wanted to make about the product suite that I don’t think is being well portrayed in the market.  To be clear, I’ve already shared the essence of this post with them in a candid conversation at CorasWorks University last week.
What I’ve found with SharePoint is that it’s really about getting together a set of very flexible and very fundamental tools and building creative things with them.  So much has been made of the content editor web part – and what it does is so simple … it emits HTML code.  How sophisticated do you have to be to write a web part that emits the HTML that is provided to it.
Some of my clients view CorasWorks in a similar way … how hard is it to roll up a few lists?  Frankly, not that hard.  However, that’s focusing on the tactical problem without taking a step back.  Rolling up a few lists is trivially simple.  Creating a framework for managing that rolled up data, providing a complete set of views, providing support, etc. is where it gets hard.
The navigational components that are provided with CorasWork’s suite are fundamental and perhaps even some what trivial – however, they are – for the most part – a good set of tools that do provide great flexibility and most of the fundamentals that you need.
In fact, the biggest complaint I have about the navigational components is that the current released version doesn’t support relative paths.  This is eating me alive at my current client as we try desperately not to bind in any environment specific configuration into out site definitions and other files.  Although it’s an up-hill challenge, I’m hoping that they will add relative path support to their Special Site Navigation component.  (I’d love to hear your comments if you’re struggling with the same issue.)
Their other navigation tools, Workplace View Advanced, and the SPS cousin are more sophisticated but are limited to the two dimensional movement through a site or area hierarchy.  It’s useful for site-to-site navigation but doesn’t help when you need to link applications within a portal together.
I mentioned that they are fundamental building blocks.  What I have been most impressed about as I’m installing CorasWorks into my third large scale implementation is it’s ability to grow with the environment.  Through the use of some undocumented properties (that I’ll likely blog about soon) it’s possible to gain very fine-level control of how things appear.  This means that tools that may originally fill a specific niche around roll ups may grow up into a set of tools that continue to drive the core of the portal for years to come.
So if you’re researching CorasWorks and wonder if it will get a few users or many users – think along the side of many users.  When you learn all of the advanced tricks it’s really amazing what you can do with the tool – including very customized menus and spectacular roll ups.  I’ll start posting on how to do a few of these things in the coming weeks.  For now, just know that there are plenty of undocumented or under-documented features just waiting to be unleashed.  Know that these features aren’t being discussed much in the market — they’re seen as an entry level tool which is useful to get started, however, the amount of “runway” that you have with CorasWorks is pretty substantial.

Code Snipit Management Tools — Why?

Perhaps it’s because it’s late while I’m writing this … perhaps I’ve missed some big revolution in software development but I don’t understand…

Why do we need code snipit tools?  Shouldn’t we have classes and methods (even if they’re static) rather than fancy tools to do the same copy-paste routine we’ve been telling developers not to do for 30 years?

Why can’t we all make an effort to put our code in reusable “chunks”?

How to Copy a Web Part

This how to describes the process for copying a web part.

  1. Open a SharePoint site.
  2. Make sure you’re in Shared Mode.
  3. Enter design mode
  4. On the web part to copy, click the down arrow on the right and select export.
  5. Save the file on your system
  6. Go to the site where you want the control added
  7. Enter Shared Mode
  8. Select Add Web Parts-Import
  9. Browse to the file and click import
  10. Drop the web part on the page.

You’ve now copied a web part from one web page to another.  Note that this won’t work for ListViewWebParts or ListFormWebParts.

How to Strong Name a Web Part

Strong Naming web parts helps to make sure that they can not be tampered with – just like signing any .NET assembly does.  However, because of the nature of SharePoint, there are a few additional steps that are required after the assembly is strong named to ensure that the web part can be deployed and correctly loaded.

The process involves two major steps: Strong Naming the Assembly, Changing the DWP file(s).

Strong Naming the Assembly

Strong naming the assembly is covered in a separate document. Signing the web part assembly itself is no different than any other .NET assembly. See How to Strong Name an Assembly

Changing the DWP File(s)

The DWP file that Visual Studio creates uses the name of the assembly without a strong name.  The fully identified assembly name must be used to load all strong named assemblies, so if the DWP file is not modified it will fail to load the assembly – and you’ll get an error message that the control is not marked as safe.

The quickest way to get the correct assembly definition in the DWP file is to use GACUtil – which installs the DLL into the GAC.  The process for getting the full assembly name and adding it into the DWP appears below:

  1. Open a command prompt and navigate to the project’s bin\debug directory.
  2. Type GACUTIL /I MyAssembly.dll where MyAssembly.DLL is the name of the assembly for the project.  You’ll see a message that the Assembly was successfully added to the cache.
  3. Type GACUTIL /u MyAssembly where MyAssembly is the name of the assembly for the project – without the DLL extension.  You will see a set of messages which show the full name of the assembly including it’s publickeytoken.
  4. Copy the Uninstalled line, including any additional information that appears on the next line to the clip board.
  5. Go to Visual Studio and open the DWP file.
  6. Paste the copied text between the and tags replacing what was there.

How to Create a Deployment CAB project

Deployment of web parts is done through CAB files.  These cab files contain a manifest.xml file that explains the contents of the CAB file, at least one DWP file which specifies the properties for a web part and normally one or more DLL files which are the executing code for a web part.
Visual Studio creates a template Manifest.xml and a sample DWP file for you when you create a new SharePoint project.  This “how to” document will show you how to create a CAB file project in Visual Studio.  Follow these steps to create the cab file project:
  1. Right click the solution in Visual Studio and select Add-New Project.
  2. In the Setup and Deployment Projects select Cab Project
  3. Enter a name for the project. Ideally this is the name of the web part project followed by “CAB”.
  4. Verify that the Location is the correct location.
  5. Click the OK button
  6. Right click the new cab project, Click Add-Project Output
  7. In the project drop down in the dialog that appears select the project file of the web part – if necessary.
  8. Click Primary Output and hold the control key down while clicking Content Files so that both are selected.
  9. Click the OK button.

If you need to add additional DWP files to the project, make sure to set their build action to content.  This can be done by selecting the DWP file, right clicking, selecting properties and setting build action to content.

How to Strong Name an Assembly

A strong name is a cryptographic public/private key pair that is applied to an assembly in order to prove that it has not been tampered with after compilation.  The process of strong naming an assembly has three components: creating the key, adding the key to the project, and adding the key to the assembly.  We’ll look at each part in turn.

Creating the Key

The process of creating the key is relatively straight forward as Visual Studio ships with a utility that creates the key for you.  Follow these steps to create the key:

  1. Start a Visual Studio Command prompt.
  2. Navigate to the project directory for the project.
  3. Enter the command ‘sn –k myproject.snk’ where myproject is the name of the project.  The key that is created will have the name of myproject.snk.
  4. Close the command prompt.

You now have a strong name key which can be added to the project.

Adding the Key to the Project

Now that you have the key, you need to add it to the project.  This is done to ensure that Visual Studio will manage the check in and check out process for you.  Follow these steps to add the key to the project:

  1. Right click the project, select Add, Add an existing item
  2. Change the Files of type drop down to All Files (*.*)
  3. Select the myproject.snk file and Click the OK button.  As before myproject should be replaced with your project name.
  4. Select File-Save All from the menu.

You’ve now added the key to the project.  It will be checked in and out when you select those commands in Visual Studio.

Adding the Key to the Assembly

The final step in the creation of a strong name is to add the key to the assemblyinfo.cs file.  This file was already added to your project for you.  Here’s how to add the key to the assembly:

  1. Open the AssemblyInfo.cs file.
  2. Locate the line [assembly: AssemblyKeyFile(“”)]
  3. Swap the set of double quotes with @”..\..\myproject.snk” so that the line looks like [assembly: AssemblyKeyFile(@”..\..\myproject.snk”)].  As above, replace myproject with your project name.  Note that the at sign says to C# that you don’t want to use escape characters.  The pairs of periods are parent directory transitions.  These are needed since the signing process takes place in either the bin\debug or bin\release directories – thus the key file, which is in the root of the project, is two levels above the assembly.
  4. Save the file.

You’re successfully added a strong name to an assembly.

Article: Concrete Code for a Quick Configuration

In my last article, ” Caught Up in Code, or Quick Configuration”, I proposed that you build more configuration based software solutions and less software that is governed by the relatively rigid rules of code alone. That article focused on the concept of configuration-based development. In this article the focus is on using the patterns for implementing a configuration-based solution.

A Few Examples

Before we drop into the details of a code sample, here are a few quick examples of how you can apply the configuration based pattern in the code you’re writing.:

  • Factory Pattern – Using reflection, generics, interfaces, and a configuration file, you can create a strongly typed factory that can generate objects of any type. You wouldn’t have to worry about ever building another factory class.
  • Optional Display – User Interface trimming, in other words, removing items from a menu when the user doesn’t have access to them is a time consuming process. However, a control can be built uses a list to determine the menu options and performs the security check as a part of drawing the menu. You wouldn’t have to worry about trimming my UI because the control manages security automatically.

Recent Posts

Public Speaking