Archive

Archive for the ‘SharePoint’ Category

Using Managed Metadata and Content Type Syndication in a Blank Site Collection

February 26th, 2011 Richard 1 comment

Recently I was using testing the Managed Metadata Service to share Content Types via Content Type Hub Syndication. I created my content types in the hub and had the Managed Metadata Service all set up and my web application was subscribed to it.

So I created a new blank site collection to test the synchronisation of my content types, but no matter what I tried, they just didn’t show up. I checked all the setting on the Managed Metadata Service, ensured that the content types were published and manually ran the Content Type timer jobs, but all to no avail.

Finally, after some searching on the internet I tracked down the problem. To subscribe to the content type hub the feature TaxonomyFieldAdded needs to be enabled. This is a hidden feature so can only be enabled programmatically or via PowerShell for which the command is

Enable-SPFeature–Url "http://mysiteurl" -Identity "73EF14B1-13A9-416b-A9B5-ECECA2B0604C"

where the guid 73EF14B1-13A9-416b-A9B5-ECECA2B0604C is the id of the feature.

Once this feature is enabled you will get the Content type publishing link in Site Settings

contenttypesettings

and the published content types immediately appeared in the site collection’s Site content types.

This feature also enables the use of Managed Metadata columns in lists. Without the feature enabled you get this error when trying to use a Managed Metadata column:

metadataColumnError

which renders the column useless. As soon as the feature is enabled then you can use it as normal.

Note, that this problem only occurs in site collections which have been created as a blank site. It does not affect blank sites created within other site collections created from another template. The reason for this is that there is another feature called TaxonomyFeatureStapler which staples the feature to most other sites, with the notable exception of the blank site. I can only assume that it’s this way because the blank site template is supposed to be a base site and have minimal functionality. If you regularly create blank site collections and need to use Managed Metadata on them you should be able to create your own feature stapler to add the TaxonomyFieldAdded feature to the blank site template.

Categories: SharePoint Tags: ,

Using PowerShell to Bulk Upload Files to SharePoint

January 6th, 2011 Richard 2 comments

While building a school’s Learning Gateway I needed to bulk upload all their student images into a picture library so that the My Children web part could display them. Since there were several hundred of them I wrote a little PowerShell script to perform this.

$siteUrl = "http://sharepoint/schools/test"
$listName = "Students Picture Library"

[system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint")
$site = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$web = $site.OpenWeb()$list = $web.Lists[$listName]
$fileCollection = $list.RootFolder.Files

$files = get-childItem -Exclude *.ps1

foreach ($file in $files)
{
    $stream = $file.OpenRead()
    $uploaded = $fileCollection.Add($file.Name, $stream, $TRUE)
    "Uploaded " + $file.Name

    if ($stream) {$stream.Dispose()}
}

if ($web) {$web.Dispose()}
if ($site) {$site.Dispose()}

In order to use this:

  1. Save as as .ps1 file in the same folder as the files to upload.
  2. Change the site url and name of the list at the beginning of the script to your values
  3. Make sure that only the files to upload and the ps1 file is in the folder
  4. Open PowerShell using Run As Administrator
  5. Navigate to the folder
  6. Run the .ps1 file

The script will then iterate through all files in the current folder and upload them to the given list, overwriting them if they already exist.

Update a Dll in the GAC From the Command Line

July 7th, 2010 Richard No comments

I’ve blogged before on how to Easily add a dll to the GAC, but that involves two instances of Windows Explorer and the mouse.

It would be quicker and easier to use the command line to update a dll in the GAC. You can do this with the Global Assembly Cache Tool gacutil, but this is only present if you have the .net SDK or Windows SDK installed. This is going to be the case with your development machine, but you don’t really want to be installing it on all your test servers.

To get round this I knocked up a quick utility which will remove an existing version of a dll from the GAC and then install the latest version. The code is:

using System;using System.Globalization;using System.EnterpriseServices.Internal;

namespace Test{    public class GacInstall    {        public static void Main(string[] arguments)        {            try            {                string assemblyPath = arguments[0];                Publish publish = new Publish();                publish.GacRemove(assemblyPath);                publish.GacInstall(assemblyPath);            }            catch (Exception e)            {                Console.WriteLine(e);            }        }    }}

You can then use it by passing it the dll you want as a command line parameter e.g.

GacInstall MyUpdatedCode.dll

Assuming that MyUpdatedCode.dll is in the same directory.

Combined with my last tip Recycle An Individual Application Pool From The Command Line you can now write a bat or cmd file to replace the dll in the GAC and recycle the application pool with 2 key presses: The up arrow key and then return.

Delete Multiple Web Parts From a SharePoint Page

June 13th, 2009 Richard No comments

If you ever need to quickly delete multiple web parts from a SharePoint page, there’s a quick and easy way.

Just add ?contents=1 to the end of the url, directly after the .aspx. If there’s already a query string there (the bit after the ?) then delete it and replace with contents=1.

For example to delete multiple web parts from http://cmis/sites/mis/default.aspx use http://cmis/sites/mis/default.aspx?contents=1.

You can then select multiple web parts and hit delete to get rid of them all at once.

webPartMaintenance

This is also useful for getting rid of web parts which cause fatal errors on the page and closed web parts.

Categories: SharePoint Tags:

European Best Practices SharePoint Conference

March 25th, 2009 RichardWillis No comments

I’ve finally got round to booking this. It’s on 6-8 April in London and looks like it will be a great conference. Don’t miss Andrew and Alex’s lunchtime session on Wednesday about SharePoint in Education. Find out more on their web site.

If anyone else is going it would be great to meet up. If anyone is interested we could try to find some space for an SLK discussion group. Let me know if you are interested in either of those and I’ll see what we can arrange.

Categories: SharePoint Tags:

SharePoint Manager 2007

March 3rd, 2009 RichardWillis No comments

I’ve just come across a great free tool for SharePoint 2007. It’s SharePoint Manager 2007 and is hosted over at CodePlex. It’s quite simply an object model explorer for SharePoint, allowing you to drill down into any detail of SharePoint, from server properties, to web users even down to individual list items. It will even let you modify the properties if you’re feeling brave.

I’ve lost count of all the little console utilities I’ve written to dump things like list fields, view CAML etc, all of which you can browse to with the tool. I think that it’s going to save me a lot of time and increase my knowledge of SharePoint.

Categories: Development, SharePoint Tags:

Finding out if SharePoint Objects are Disposed Correctly

February 27th, 2009 RichardWillis No comments

Everyone should know by now that certain SharePoint objects, including SPSite and SPWeb need to be disposed of when you have finished with them or you will get a memory leak. If you want to refresh your memory have a look at the MSDN white papers Best Practices: Using Disposable Windows SharePoint Services Objects on MSDN and Best Practices: Common Coding Issues When using the SharePoint object model.

What you may not know is that there are a couple of tools/techniques which can help you find areas in your code where you are not disposing of objects correctly.

  1. SPDisposeCheck. This is a tool which will analyze your assemblies to search for coding patterns which lead to objects not being disposed correctly. It’s a great tool and worth running regularly on your assemblies.
  2. SPRequestStackTrace registry value. Creating the registry key

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\HeapSettings
SPRequestStackTrace: DWORD = 1

Will cause the SharePoint runtime to log a stack trace everytime a SPRequest object is not disposed of correctly. This will actually pick up all the types of objects not being disposed of as internally the problem with not disposing of them is that they contain a reference to SPRequest.

At this point I have to say thank you to Jared Kahlil who pointed out a memory leak in the SLK by using the second method above and started my research into both of these methods. Unfortunately we can’t use SPDisposeCheck on SLK as it checks to see if the file name begins with Microsoft and if there are any namespaces beginning with Microsoft, and if so ignores the assembly.

Categories: Development, SLK, SharePoint Tags:

My Sites in Schools

January 21st, 2009 RichardWillis No comments

I’ve had several conversations with several schools about MOSS My Sites. A lot of people are finding that they are too powerful and the pupils have too much control over what they can do in them. Personally I think that they are a great tool for collaboration and would let them loose with them, possibly after some modification to the default (see my previous post) and trialling it with a subset of the school, but I don’t actually work in a school and deal directly with the problems that might cause.

However, for those who don’t want to do this, an alternative would be to create sites for the pupils within your normal SharePoint structure, just like your class sites under the Classes tab in MLG. You’ve then got all your normal permission levels and restrictions you can use, and generally tie it up a lot tighter. You can even define custom permission levels. I’m working with a few schools on implementing this for pupils and staff using Salamander SharePoint.

Taking it to another level, a request I’ve just received from one school is:

I am quite interested in developing a
SharePoint site, similar to the class sites for every teacher.
Giving them a kind of My Site where they could post resources, links and a profile etc.  I would need the script to create a site for each member of staff based on a template and then assign permissions for the teacher and then for all the students that the teacher teaches. 

This is actually quite powerful and really easy with Salamander SharePoint. It sets up collaboration sites and also the community which can use them, and automatically keeps this community up to date. It’s requests like these which can add another level to how SharePoint is used in your school.

Categories: My Sites, SharePoint Tags:

Customising My Sites

January 21st, 2009 RichardWillis No comments

I’ve been asked a few time about how to customise the MOSS My Sites. Unlike SharePoint 2003, the reality is that it’s not easy. It may seem like a retrograde step, but as they are so powerful, adding a facility to modify all of them becomes difficult.

The easiest and most obvious way, altering the templates, is not supported as they are considered a core part of SharePoint. It will work, but Microsoft do not guarantee that they won’t be overwritten in any upgrade.

That leaves the only way is by running some custom code. This isn’t great for anyone who isn’t a developer.
If you want how it’s done, Steve Peschka has some great information on how to do this on his blog. Even better than this, he has wrapped it all up as part of the Community Kit Project for SharePoint on CodePlex and released it as MySiteCreate.

What MySiteCreate allows you to do is specify a different master page for the My Sites and also specify web parts and their properties in an xml file. No more messing around with code, just a great tool to let you get on with the job.

Categories: My Sites, SharePoint Tags:

Another Microsoft Technet article mentions SalamanderSoft

December 16th, 2008 RichardWillis No comments

SalamanderSoft has been mentioned in another TechNet article, this time about Blatchington Mill School which is titled Example Solution Architecture: Blatchington Mill School. Congratulations to Mark & Sue for all their hard work developing their portal being recognized by Microsoft.

Interestingly it the My Documents web part which is explicitly mentioned, while Salamander SharePoint which is used to generate the class sites is referenced as a third-party provisioning tool. Salamander SharePoint is much more powerful than My Documents so it’s strange we’re mentioned in relationship to one and not the other.

Categories: SharePoint Tags: