using System; using System.Text; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; 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); } } } } } }