using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using System.Web;
using Microsoft.SharePoint.Administration;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please input url");
string siteurl = Console.ReadLine();
string[] temp = System.IO.File.ReadAllLines("userid.txt", System.Text.Encoding.UTF8);
foreach(string struser in temp)
{
string[] arruser=struser.Split(‘|‘);
string Keyaccount = arruser[0];
Uri webAppUri = new Uri(siteurl);
SPWebApplication webApplication = SPWebApplication.Lookup(webAppUri);
string newName = arruser[1];
string newEmail = arruser[2];
foreach (SPSite siteCollection in webApplication.Sites)
{
using (SPSite oneSite = new SPSite(siteCollection.Url))
{
using (SPWeb webApp = oneSite.OpenWeb())
{
foreach (SPUser spuser in webApp.SiteUsers)
{
if (spuser.LoginName.ToUpper() == Keyaccount.ToUpper())
{
try
{
string oldname = spuser.Name;
string oldemail = spuser.Email;
string url = webApp.Url;
spuser.Name = newName;
if (!string.IsNullOrEmpty(newEmail.Trim()))
{
spuser.Email = newEmail;
}
spuser.Update();
FileStream fs = new FileStream(System.Environment.CurrentDirectory + @"\log.txt", FileMode.OpenOrCreate, FileAccess.Write);
System.IO.StreamWriter sw = new System.IO.StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.End);
sw.WriteLine(DateTime.Now.ToString() + " " + "Site:" + url + " Account:" + spuser.LoginName + " Name:" + oldname + " change to " + spuser.Name + " email:" + oldemail + " change to " + spuser.Email);
sw.Flush();
sw.Close();
fs.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + ex.StackTrace);
}
}
}
}
}
}
}
}
}
}