SharePoint modifies users and groups display name and email address C # code

Source: Internet
Author: User

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);
}
}
}
}
}
}
}
}
}
}


This article from "Bo shen" blog, reproduced please contact the author!

SharePoint modifies users and groups display name and email address C # code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.