在SharePoint 2010上,我有许多包含表格的wikipages。是否可以使用客户端对象模型在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
答案 0 :(得分:0)
由于维基内容存储在关联的列表项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 property用于检索List Item
与File