首页 > 代码库 > sharepoint 修改用户和组 display name 和 email地址 C# 代码
sharepoint 修改用户和组 display name 和 email地址 C# 代码
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);
}
}
}
}
}
}
}
}
}
}
本文出自 “博深” 博客,转载请与作者联系!
sharepoint 修改用户和组 display name 和 email地址 C# 代码