编程语言
首页 > 编程语言> > Delete field (column) from a SharePoint list Using C#(CSOM)

Delete field (column) from a SharePoint list Using C#(CSOM)

作者:互联网

string strUrl = ConfigurationManager.AppSettings["SiteUrl"];
string strWebUrl = ConfigurationManager.AppSettings["WebUrl"];
string strListName = ConfigurationManager.AppSettings["ListName"];
string strFieldName = ConfigurationManager.AppSettings["FieldName"];

            Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(delegate ()
            {
                using (SPSite site = new SPSite(strUrl))
                {
                    using (SPWeb web = site.OpenWeb(strWebUrl))
                    {
                        web.AllowUnsafeUpdates = true;
                        SPList list = web.Lists[strListName];
                        if (list != null)
                        {
                            foreach (SPField field in list.Fields)
                            {  
                                if (field.Title == strFieldName)
                                {
                                    field.AllowDeletion = true;
                                    field.Delete();
                                    list.Update();
                                    break;
                                }
                            }
                        }
                        web.AllowUnsafeUpdates = false;
                    }
                }
            });

            Console.WriteLine("Success");

        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

标签:web,string,ConfigurationManager,column,AppSettings,CSOM,SharePoint,list,field
来源: https://www.cnblogs.com/selenazhou/p/14389014.html