All posts by David Wise

Deleting Orphan Template Files from SharePoint 2007 for Upgrade to 2010


I’ve been working on knocking out some issues from the Pre-Upgrade Check Report in order to get ready for our upgrade to SharePoint 2010 and recently hit one heck of a snag where certain artifacts that were created way back in 2003 were somehow still being referenced but not actually used anywhere in 2007.  These items never existed in the 2007 file system and were certainly not visible in any way from the UI.

The items appeared under the “Missing server file or server configuration issues” section of the report under the specific title of “The following setup file(s) are referenced by the content, but they are not installed on the web server”.  They were part of old Site Templates that were fortunately all named starting with “STSFA”.  To find out where SharePoint thought these items were required diving into the content database (Sorry, but the additional data Microsoft provides for these errors is close to useless)  the SQL used is below but the fields of concern are DirName and LeafName:

select * from AllDocs with (nolock)
    where SetupPath like 'SiteTemplates\STSFA%' 
    order by DirName

In my case, I had the following URLs that were being kicked out – “/RealFolder/03folder/default.aspx”. RealFolder exists (obviously) but 03Folder does not, yet SharePoint claimed it did on the Pre-Upgrade report.

It turns out that these items were in a state where, depending on how you looked at them, they were either orphaned or were not orphaned.  Go ahead, put on your Kenobi robe on and wrap your brain around that, I’ll wait.  Back?  Ok, good.  Perhaps a better term for these types of items might be “disowned” rather than orphaned.

After some digging in the Object Model, it turned out that if you use certain methods to access the item, like GetFile() or GetFolder() that it could see the items but it only returns a subset of the data that SharePoint has about the object. The objects returned from these methods always had several properties, including ParentWeb listed as empty. When I attempted to call .Delete() on the item, it would throw the ever popular “Object or reference not set…” exception.

The PowerShell below is a summary of how I got past that issue and it includes the comments as to why the steps are there.  Yes, I could have written this as a C# console application as well, but I wanted to keep it in PowerShell so that the other Admins would know exactly what the script was doing.

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[Microsoft.SharePoint.SPSite]$site = [Microsoft.SharePoint.SPSite]("http://SiteUrlGoesHere/")
$fileUrl = "http://SiteUrlGoesHere/RealFolder/03Folder/default.aspx"

#get a handle to the web that thinks it contains the orphan
[Microsoft.SharePoint.SPWeb]$parentWeb = $site.OpenWeb($fileUrl, $false)

#Get a handle to the object itself.  
#for some reason, this call brings back way more information than GetFile(), 
#not the least of which is the Guid to the actual object $tempFile = $parentWeb.GetObject($fileUrl) #use the Guid to get the real object [Microsoft.SharePoint.SPFile]$oldFile = $parentWeb.GetFile($tempFile.UniqueId) #Now make all your dreams come true #oldFile.Delete() #but don't forget to clean house $parentWeb.Dispose()

I tried about 7 variations on the above method, including trying to open the items from the root of the site, using GetFile() directly, etc..  This was the only version I tested that actually deleted the items from the SharePoint database. 

The best part about this is that the update is done completely via the Object Model so it is a fully supported way to cleanup these types of orphaned files.

Debugging Powershell Modules in Visual Studio 2010


There are posts all over the web lamenting how difficult it is to debug a custom PowerShell Module from within Visual Studio 2010 but I found a simple way to do it that works every time.  It was tricky to get right at first, but this works like a champ.

Here are the steps:

  • Start Visual Studio
  • go the the Properties window for your custom Module Project
  • Select the ‘Start External Program’ radio button
  • enter “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe” as the destination.  This will start PowerShell and attach the debugger to the instance

DebugPowerShellExternalProgram

  • Go down to the “Start Options” and enter the text below in the “Command Line Agruments” box, including all of the quotes (naturally, you will have to change the paths for your project):

-noexit -command “& { import-module -name ‘C:\Path\To\Solution\Project\bin\Debug\CustomModule.dll’}”

DebugPowerShellCommandLine

This last step loads your custom module into the PowerShell instance that is being debugged.  From there, simply set your breakpoints in Visual Studio and then call your new PowerShell command from within the new PowerShell window.  It should stop on your breakpoint every time.

Happy Debugging!

Just moved in!


Hey!  It’s me, I’m back, at least for a while.

I have been out of the blog world for a few years but am back now and hopefully will be able to kick out some decent posts.  They won’t be frequent but should be useful.

The old blog is still is still alive over on VSPug but I will fully move from there in a few weeks.  I am very grateful to the operator over at VSPUG who keeps that site running out of his own pocket!  Hopefully, getting my content off there will help him move a little closer to freeing up some pocket change 🙂

I’ve brought all of my original posts here just to keep everything together but please bear in mind that many of these posts relate to SharePoint 2007, and often even pre SP1.  If you hit something that just ain’t right, drop me a note and I’ll see if I can’t get it cleaned up.

Also, I am new to this blogging software so please bear with me while I figure out what all the knobs, buttons and levers do.  I know not to press the big red one, though.  Big shiny red buttons are always ‘bad’

Custom Site Columns missing from Search Metadata Properties


I have been working a lot more with SharePoint search lately and have been enjoying it for the most part.  Except recently when I started seeing a problem where my custom site columns were not appearing in the list of available Metadata Properties in Search Administration.

After a great deal of research and experimentation, the problem turned out to be that the standard SharePoint Http Response Header was either removed from IIS or was never added.  In either case, adding this header back in let the crawler in to see all of the appropriate metadata

Name : MicrosoftSharePointTeamServices
Value : 12.0.0.6341

This is set in Start –> Control Panel –> Administrative Tools –> IIS Manager –> [Your Server] –> Sites –> [Your SharePoint Site]  -> HTTP Response Headers

Once I had figured out the answer, I started looking for more information about why that header seems so important.  Nothing.  I did discover that if you search only the Microsoft site for this header, you will find all sorts of SharePoint related mischief when it is missing, from bad Urls to authentication errors and beyond.

My guess is that the crawl uses this to determine how it should attempt to index a site.  If it sees this header then it crawls it as a SharePoint site (including all metadata) but if it doesn’t, it then treats the site as a standard web site.  Experimentation bears this out.  I created a test case where my primary navigation control was not visible during a crawl.  If I remove the header, the index can only see  the links directly on the home page, but if I add the header and do not change anything else, it crawls everything in the SharePoint site, even though there is no navigation pointing to those pages.

Some detailed information from Microsoft about this header would be nice as I know that some security professionals advocate stripping all http response headers out of websites in order to minimize surface area. I can easily see a situation where this condition would be created.

Silverlight XAP File Out of Date When Built with Expression Blend


 

The latest project I am working on involves some rather tight integration between Silverlight and SharePoint so I'm getting my feet wet with these tools in the SharePoint-o-Sphere.

I recently ran into an issue where the .XAP file that is needed for Silverlight would not update properly whenever I built the solution within Expression Blend.  If I switched over to Visual Studio, then it would work perfectly.  A quick search showed no conclusive fix for this issue so I came up with this bute force workaround:

  1. Close Blend
  2. Open Visual Studio
  3. go to Project -> Properties -> Build Events and enter the line below in the Post-build event (replacing the web name as needed)

xcopy /y "$(TargetDir)$(TargetName).xap" "$(SolutionDir)sample.webClientBin"

After that, the build works fine in both Visual Studio and in Blend.

I should point out that when I initially created this solution the build worked fine in both Blend and Visual Studio.  The Blend build stopped updating the XAP file when I restructured the solution in order to put the projects into Team Foundation Server.  I cannot find anything in the folder structure itself that points to the old folders or structure so I am not sure where this behavior is coming from.