vb.net客户端对象模型:从sharepoint2010wikipage查看内容



在SharePoint 2010上,我有许多包含表的Wiki页面。是否可以使用客户端对象模型在vb.net中查看该页面的内容?

我试图使用流获取文件代码,但我得到的文本是很多asp.net代码,但不是该页面的html代码/内容。。。

Dim fileAlgemeen As SP.File = Nothing
Dim siteUrl As String = "https://portal.xx.be/sites/kdb"
Dim ctx As New ClientContext(siteUrl)
Dim credentials As NetworkCredential = New NetworkCredential("xx", "xx")
ctx.Credentials = credentials
Dim web As Web = ctx.Web
ctx.Load(web)
ctx.ExecuteQuery()
Dim relativeUrl As String = "/sites/kdb/596/Algemeen.aspx"
Dim file As SP.File = web.GetFileByServerRelativeUrl(relativeUrl)
ctx.Load(file)
ctx.ExecuteQuery()
Dim fileRef = relativeUrl 
Dim fileInfo As FileInformation = SP.File.OpenBinaryDirect(ctx, fileRef.ToString())
Using fileInfo.Stream
    Using sr As StreamReader = New StreamReader(fileInfo.Stream)
        Dim line As String = sr.ReadToEnd()
        lbl.Text = line
    End Using
End Using

由于wiki内容存储在关联的列表项PublishingPageContent字段中,因此无需读取文件内容。

以下示例演示了如何使用SharePoint CSOM(VB.NET)读取更新wiki内容

Sub Main()
    Const siteUrl As String = "https://contoso.sharepoint.com/kb/"
    Const userName As String = "username@contoso.onmicrosoft.com"
    Const password As String = "password"
    Using ctx = New ClientContext(siteUrl)

        Dim credentials As NetworkCredential = New NetworkCredential(userName, password)
        ctx.Credentials = credentials
        '1. Read Wiki content 
        Dim wikiFile = ctx.Web.GetFileByServerRelativeUrl("/kb/Pages/Welcome.aspx")
        Dim wikiItem = wikiFile.ListItemAllFields
        ctx.Load(wikiItem)
        ctx.ExecuteQuery()
        Console.WriteLine(wikiItem("PublishingPageContent"))
        '2. Update wiki content
        wikiItem("PublishingPageContent") = "<h1>Welcome to the SharePoint!</h1>"
        wikiItem.Update()
        ctx.ExecuteQuery()
    End Using
End Sub

要点:

  • Wiki内容存储在List Item PublishingPageContent字段中

  • File.ListItemAllFields属性用于检索List ItemFile 相关

相关内容

  • 没有找到相关文章

最新更新