【问题标题】:Programmatically Add New Choice to Choice Column in SharePoint List以编程方式将新选项添加​​到 SharePoint 列表中的选项列
【发布时间】:2019-06-18 14:30:06
【问题描述】:

我正在与一位客户合作,并试图做到这一点,以便在按下按钮打开新的会计年度 (FY) 表单时,它还会将该 FY 值添加为文档库列中的选择选项。我也在尝试将默认值设置为该新值。

我收到以下错误。

这是我当前的代码。这只是一个配置问题吗?还是我在用我的代码做一些事情?

Imports Microsoft.SharePoint
...
Partial Class _Default
    Inherits System.Web.UI.Page
...
Protected Sub SaveNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SaveNew.Click

 ...

                'Added 6/12/2019 - Testing new FY options in Document Upload Form
                Using site As New SPSite("http://sptest/spsite/default.aspx")
                    Using web As SPWeb = site.OpenWeb()
                        Dim leadLst As SPList = web.Lists("Document Library")
                        Dim col As SPFieldChoice = CType(leadLst.Fields("Fiscal Year"), SPFieldChoice)
                        col.Choices.Add(FY.Text)
                        col.DefaultValue = FY.Text
                        col.update()
                        leadLst.update()
                    End Using
                End Using
                'End Added 6/12/2019

 ...

End Sub

【问题讨论】:

    标签: vb.net sharepoint sharepoint-2010


    【解决方案1】:

    当您创建 SPSite 的对象时,您只需要传递网站集的 URL,而不是 .aspx 页面 从

    转换您的 SPSite 对象创建行
     Using site As New SPSite("http://sptest/spsite/default.aspx")
    

    Using site As New SPSite("http://sptest/spsite/")
    

    如果 spsite 是您的子网站,并且上面的代码不起作用,则将该行转换为

    使用站点作为新的 SPSite("http://sptest/")

    然后为 spsite 子站点获取 SPWeb 对象

    让我知道这是否有帮助?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-01
      • 2016-12-30
      • 2011-10-15
      • 1970-01-01
      • 2010-10-20
      • 1970-01-01
      相关资源
      最近更新 更多