sharepoint 修改用户和组 display name 和 email地址 C# 代码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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# 代码的主要内容,如果未能解决你的问题,请参考以下文章

SharePoint CSOM 处理人员和组字段

linux系统下怎么修改文件所属用户和组?

Linux修改文件或目录所属用户和组

Linux修改文件或目录所属用户和组

修改Nginx用户和组!

修改Nginx用户和组