Archive for the ‘SharePoint’ Category

Creating a Publishing HTML field in SharePoint programmatically

Sooooooo, creating a Publishing HTML field in SharePoint (think wiki Page Content field) is a huge pain (well, the solution is easy, but the figuring it out part was a pain).  However, because I’m extremely busy, I’m going to skip the part where I explain all the hundreds of things I’ve tried and why they all failed, and move straight to the solution:


$web = Get-SPWeb “http://dev01”;
$spList = $web.Lists[“Pages”];
$newField = “<Field Type=’HTML’ DisplayName=’FieldName’ RichText=’TRUE’ RichTextMode=’FullHtml’ />”;

Categories: SharePoint

SPS Presentation

I just wanted to post a link to my SharePoint Saturday Presentation.  Thanks to everyone for attending and making my first presentation a good one!

Download the slides here

Download the ULS Log Adapter here

Categories: SharePoint

SharePoint 2010 & HTTPS network connections

It’s really frustrating sometimes how Microsoft’s whitepapers are so specific to individual cases that they fail to apply to any useful scenario – particularly those scenarios that involve custom development.  Such is the case for making HTTPS web service calls from SharePoint 2010 (to external endpoints).

The Goal

Custom built web parts deployed into SharePoint 2010 need to make web service calls to a 3rd party API which used an HTTPS endpoint.

The Error

Could not establish trust relationship for the SSL/TLS secure channel with authority ‘[some url]’

My Flailings

The typical cause of this is that the root certificate that the SSL endpoint uses is not trusted by the computer that is attempting to make the web service connection.  The typical resolution?  Open the certificates snap-in through the Windows Management Console and add the root certificate (or even the certificate for the SSL endpoint) to the Trusted Authorities node and you’re all good.  You can even test this by navigating to the endpoint with your browser; if you get a certificate warning it didn’t work, otherwise it’s gravy.

The issue (and the reason for this blog post) is that this doesn’t work; apparently SharePoint completely ignores the machine settings for the trusted root certificates.

The Solution

It’s actually quite simple – open Central Administration and go to the security page.  Find and click the Manage Trusts link. Add a new trust, and in the window that opens upload your root server certificate, give it a good name and boom, things start working – just like magic.

I also found a nice little PowerShell script that will automate the trust creation for you:

$root = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("C:\MyRootCertificate.cer");
New-SPTrustedRootAuthority -Name "my root certificate" -Certificate $root;

SharePoint Themes and how to make them work

November 11, 2010 Leave a comment

I’ll start at the end because I think I’m going to forget this the most often:

How to get a CSS file to be compiled by the theme engine

First of all, use the CssRegistration tag.  You’ll be happy you did when you don’t have to fight with SharePoint to get your CSS file to link properly.

 <SharePoint:CssRegistration Name="<%$SPurl:~SiteCollection/Style Library/en-us/Themable/MyHome.css%>" After="corev4.css" runat="server" />

The “<%$SPurl…” ensures that the url points to the current version (themed or non themed) of the css file.  Be sure to put this tag right after the SharePoint:CssLink tag, I’ve tried putting it in other places and for some unknown reason it breaks things pretty badly.

Place your CSS file under the themeable directory under the Style Library like the URL shown in the CssRegistration tag.


The theme engine will not pick up any non-published versions, you MUST check in your CSS and image files.

Finally, apply a theme – any old theme.

You’ll notice that when you apply the theme, and look at the page source your css files will have moved into a different directory:

 <link rel="stylesheet" type="text/css" href="/_catalogs/theme/Themed/9262B884/MyHome-4277C871.css?ctag=44">

Weird huh?

When you applied the style, the theme engine picked up all the style sheets and images and performed its magic on them.  Then it saved them to this separate location.

This means that any changes you now make to your original css or image files will not be reflected in your newly themed site – yes, that’s right, you need to go back and reapply your theme to the site so the theme engine will recompile the CSS and image files.  Man that’s annoying isn’t it?!

Using themes in your CSS files

Below are a list of the theme commands you can use in your CSS file.  The commands will replace CSS attributes or recolor images as appropriate if used properly.  But first, there’s a mysterious comment at the top of the corev4.css file that I’ve noticed:

/* _lcid=”1033″ _version=”14.0.4762″
_LocalBinding */

I don’t know what it does, and as far as I can tell, this page is the first reference to this comment anywhere on the interwebs.  For now I’ll leave this at the top, because it’s there in corev4.css and I want my style sheet to be just like corev4.css when it grows up.

Next – there are a few commands that can be used to theme-up your stylesheet:

ReplaceColor(themeColor) – should be put before a color attribute (obviously), this will replace the attribute color with a color from your theme.

ReplaceFont(themeFont) – this guy works like ReplaceColor, except with fonts.

RecolorImage(themeColor, method, includeRectangle) – should be put before an image reference – ie. url(<image url>).  This will color the image in the manner specified.  The only required parameter is the color, the other 2 params are optional:

themeColor – this one’s obvious, the color to use to re-color the image.
method – options here are: Filling, Blending, Tinting
includeRectangle – defines the section of the image to recolor i.e. {x:0,y:0,width:15,height:15} defines a rectangle starting at 0, 0 pixels, and is 15px high by 15px wide.

All of the above is pretty self-explanitory with the exception of the method parameter on the RecolorImage – for this, I refer you to an excellent blog post from Microsoft’s SharePoint team in which he shows examples of each recolor method, as well as all the permutations of the different colors.

One last thing – I’ve found themes to be not an extremely awful experience, just a painful one.  However, they can be useful every once in a while in limited situations.  For these limited situations it’s probably necessary to undo all the theming that’s in the corev4.css so that you can implement themes for only the elements that you wish.  The ThemeOverride.css stylesheet will override all the style rules in corev4.css, so that no theme colors or fonts will display.

To use the ThemeOverride.css stylesheet, just insert it between corev4.css and your custom css like so:

      <SharePoint:CssLink runat="server" Version="4" />
      <SharePoint:CssRegistration Name="<%$SPurl:~SiteCollection/Style Library/en-us/Themable/ThemeOverride.css%>" After="corev4.css" runat="server" />
      <SharePoint:CssRegistration Name="<%$SPurl:~SiteCollection/Style Library/en-us/Themable/MyHome.css%>"
           After="<%$SPurl:~SiteCollection/Style Library/en-us/Themable/ThemeOverride.css%>" runat="server" />

Be sure that you specify the ThemeOverride.css in the After attribute of your custom stylesheet.  Otherwise the ThemeOverride.css will be moved after your custom style sheet and will override all of your beautiful CSS work.

Categories: SharePoint, UI

Setup incoming email for your SharePoint development VM

September 3, 2010 Leave a comment

So today I was trying to figure out how to debug an event handler on an email-enabled list.  My dev environment is running on a VM on my laptop so I didn’t really have an exchange server I could hook up to.  So, configuring the SMTP service on my Windows 2008 machine was the way to go.

In server manager, under features, click Add Feature, then select the SMTP service.  Accept the feature dependencies and finish the install.

Open the IIS 6.0 manager, and right-click your new SMTP Virtual Server node, then click properties.  Under access, ensure your authentication method is set to annonymous and your relay restrictions allow anyone.  Remember, this is just a development setup, so hopefully noone will be hacking into your new SMTP server to send out spam for Viagra.

Also, you may want to assign an alias for your domain, but that’s not required.

Next, go into Central Administration -> System Settings -> Configure incoming e-mail settings.  Select advanced settings, and at the bottom plug in your machine name and the email drop folder ‘c:\inetpub\mailroot\drop’ then hit OK.

Once that’s done we just need to enable the list to receive emails.  Just open your list (or create a new one) and go to list settings.  Under the communication section is a link for Incoming e-mail settings.  Select that and choose the settings appropriate for your list.  Note that you may want to configure this through a feature receiver or a list deployed in your solution (after all, isn’t that what we’re here for?).

Now lets deploy and debug our event receiver.  In your Visual Studio solution, click run to deploy and begin debugging the solution.  Now, although normal list event receivers are run on the w3wp.exe process, list event receivers running on e-mail enabled lists will be run by the OWSTIMER.EXE process, so use the Debug -> Attach to Process… option to find it.  You may need to check the Show processes from all users option.

Once we’ve got our event wired up and the proper process being debugged, we just need to fire up and email and see if this thing works.  So, unless you have an email client (or want to install one) on your virutal machine, back out to your host machine.  You’ll need to make sure that your host machine can connect to your VM over the network.  Now, in Outlook, go to Tools -> Account settings… In the email tab, click on New… and select the Microsoft Exchange, POP3, IMAP or HTTP option.  On the next screen, don’t enter anything, but check the box at the bottom of the screen specifying that you want to manually configure your settings, and next choose the Internet email option.

On the next screen you’ll be asked for a bunch of settings for the SMTP server, your email address, user name and password. The important thing here is to set the SMTP server to your VM server address, we don’t have a POP3 or IMAP server set up on the machine, so incoming mail won’t work, but that shouldn’t matter since we just want to send mail to our new SMTP server.  Enter in some test email, and the username and password of your development user.  Click the Test Account Settings… button and you should receive the results I got below.

If you didn’t, it’s most likely because your VM isn’t responding at the address you plugged in for your Outoing mail server (SMTP) value.  Remember, this value doesn’t need to have the domain your VM is on, it just needs to be able to find the SMTP service at that address.  One extra way to test it is to open the mail drop folder (c:\inetpub\mailroot\drop) on your VM and watch the test email file show up there, then promptly disappear when the timer job runs.

Now just create a new email and send it to your new list email address – be sure to use the new account you just created.  Type in your subject and email body and send away.

Categories: SharePoint

Renaming a SharePoint dev server

When setting up a dev server (or any server for that matter) you should always rename the machine after you’ve installed Windows and before setting up any other applications.  This is particularly true if you’re setting up a SharePoint server, as renaming the server after you’ve set up SharePoint has disastrous effects.


However, if you’ve forgotten to rename your server (like I did) and you just installed SharePoint and are getting sick of typing in names like http://win-87efgyaklq (like I am), there is a way out – as long as you’re willing to part with your content databases.  There’s probably a way to do it without losing all your content, but I haven’t figured that one out yet…


Step 1. Detach the SharePoint server from the farm.

Open the SharePoint Configuration Wizard and select “Disconnect from this server Farm”.


Click Next, Yes, then Finish.


Step 2. Rename the Server

Don’t forget to do it this time… it’s the whole reason we’re going through this mess.

Now we want to recreate the farm, but first we want to clean out all the content databases, since we really can’t use them (they have references to the old machine name).


Step 3. Delete the SharePoint content & configuration databases

Fire up SQL Server Management Studio and log into your database.  Open the Object Explorer Details and highlight all of your SharePoint Databases.  Note my Forms Based Auth. database below can stay as we can still use this after the machine name changes.


Right Click -> Delete.  You’ll probably want to check the box that says to close all existing connections before deleting otherwise you’ll get a few errors (SharePoint keeps DB connections in its connection pool open for a while).


Step 4. Recreate your farm

Fire up your SharePoint configuration wizard again and this time you want to create a new farm.


And that’s it, you’re done.  Well, after you create your web app and site collections, but you should already know how to do that – right?

Categories: SharePoint