views:

127

answers:

0

The code below throws an exception when I try to access the site.Rootweb property.

I suspect it is a rights issue, but no matter waht I do I cannot resolve it.

Any ideas?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace PopList
{
   class Program
   {
        [STAThread]
        static void Main(string[] args)
        {
            var listUrl = args[0];
            var count = int.Parse(args[1]);

            SPSecurity.RunWithElevatedPrivileges(() =>
            {
                var site = new SPSite(listUrl);
                var waName = site.WebApplication.Name;
                Console.WriteLine("Site: " + site.Url);

                var farm = SPFarm.Local;
                var webService = farm.Services.GetValue<SPWebService>();
                var webApp = webService.WebApplications[waName];
                site = webApp.Sites[site.ServerRelativeUrl];

                Console.WriteLine(site.RootWeb);
            });
        }
    }
}