More on SharePoint “User not found” error with Reporting Services

Following up my initial post on the SharePoint “User not found error with Reporting Services in integrated mode, I wanted to post another reason for the “User not found” error.

If, somewhere in the site author tree, you have user accounts that no longer exist, you will encounter the “User not found” error while viewing the report and browsing the list of shared data sources.

I found two good blog articles about this issue as well as a solution here:

I modified the code a bit to just show the site author without resetting it.  I also changed the code to explicitly dispose of the SharePoint objects.

The utility takes two parameters, the first is the site URL.  If you only pass one parameter, it looks up the site author.  If you pass a second parameter (in the format of DOMAIN\USER), the site author will be reset to the value you supply.

To build, run this from the command-line:

%WINDIR%\Microsoft.NET\Framework\v2.0.50727\csc /target:exe /out:SPResetAuthor.exe SPResetAuthor.cs
/reference:"%COMMONPROGRAMFILES%\Microsoft Shared\web server extensions\12\ISAPI\Microsoft.SharePoint.dll"

Source code of SPResetAuthor.cs:

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

// Original code from: http://blog.krichie.com/2008/09/12/
//      resetting-the-author-on-a-sharepoint-site-or-wherefore-art-thou-author-redux/

namespace SPResetAuthor
{
  class Program
  {
    static void Main(string[] args)
    {
      if (args.Length < 1)
      {
        StringBuilder sb = new StringBuilder();
        sb.Append("\nSYNTAX: SPResetAuthor.exe (Site URL) [new owner]  \n");
        sb.Append("\nwhere:\n\n");
        sb.Append("\n\t(Site URL) - The web URL for"
            + " the site i.e. http://sharepoint/site/");
        sb.Append("\n\t[new owner] - 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]);
      using (SPSite site = new SPSite(args[0]))
      {
        // Open the web via the URL passed in
        Console.WriteLine("Opening site (web)...");

        using (SPWeb web = site.OpenWeb())
        {
          Console.WriteLine("Site (web) title: " + web.Title);
          if (args.Length == 1)
          {
            Console.WriteLine("Attempting to retrieve author for site");
            try
            {
              Console.WriteLine("web.Author: {0}", web.Author.ToString());
            }
            catch (Exception ex)
            {
              Console.WriteLine("Exception occured:\n{0}", ex.ToString());
            }
          }
          if (args.Length == 2)
          {
            Console.WriteLine("Resetting Author to: {0}", args[1]);
            SPUser user = web.EnsureUser(args[1]);
            web.Author = user;
            web.Update();
            Console.WriteLine("Author for site {0}, reset to {1}", args[0], args[1]);
            Console.WriteLine("Author ID: " + web.Author.ID.ToString());
            Console.WriteLine("Author Name: " + web.Author.Name);
          }
        }
      }
    }
  }
}
bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark
tabs-top

Leave a Reply