Nov 20, 2009

Sharepoint and Reporting Services: User cannot be found

As you can deduce from the error, the problem is that the author of a Sharepoint web site cannot be found.

When Reporting Services tries to render a page, it seems to read the Author field of every web site of all site collections in all web applications. If the author cannot be resolved in just one web site(the user had been deleted), this fails.

You can see the same error with Sharepoint Manager 2007 tool (http://spm.codeplex.com/) by browsing to a web site and viewing the Author field.

I copied code from this blog post (http://blog.krichie.com/2008/09/12/resetting-the-author-on-a-sharepoint-site-or-wherefore-art-thou-author-redux/) to reset the Author field for sites that have this error in a site collection.

Here's the modified code:

// BEGIN SPResetAuthor

using System;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace SPResetAuthor
{
class Program
{
static void Main(string[] args)
{
if (args.Length < 2)
{
string sFormat = "{0,5}{1,-20}{2}\n";
StringBuilder sb = new StringBuilder();
sb.Append("\nSYNTAX: SPResetAuthor.exe webURL DOMAIN\\USER \r\n");
sb.Append("\nwhere:\n\n");
sb.AppendFormat(sFormat, " ", "", "The Web URL where"
+ " the author needs to be reset");
sb.AppendFormat(sFormat, " ", "", "The Login Account"
+ " for the new author, i.e. DOMAIN\\USER");
Console.WriteLine(sb.ToString());
return;
}

// Open the site collection
Console.WriteLine("Opening site collection for: {0}",args[0]);
SPSite site = new SPSite(args[0]);
String userName = args[1];

fixEmptyAuthors(site.AllWebs, userName);

}

private static void fixEmptyAuthors(SPWebCollection webs,String userName) {
foreach (SPWeb web in webs)
{
bool authorEmpty = true;

try
{
web.EnsureUser(web.Author.LoginName);
authorEmpty = false;
}
catch (Exception e)
{
authorEmpty = true;
}

Console.WriteLine("Site (web) title: " + web.Title);

if (authorEmpty)
{
Console.WriteLine("Resetting Author to: {0}", userName);
SPUser user = web.EnsureUser(userName);
web.Author = user;
web.Update();
}

fixEmptyAuthors(web.Webs,userName);

}
}
}
}

// END SPResetAuthor




Create a Console application with this code (don't forget the reference to Microsoft.Sharepoint.dll) and run the app with: spresetauthor.exe http://server:port domain\user

You'll need to run the application for all site collections you have (My Sites, SSP, etc) and I recommend the "sharepoint\system" as the new author.

Good luck!

No comments:

Post a Comment