我使用下面的代码使用Microsoft.SharePoint.Client将文件上传到SharePoint Online
上传文件后,会在库中创建新记录-如何获取该记录的ID?我想重新加载该记录以读取SharePoint中的计算字段(上传后计算得出)。
FI = New IO.FileInfo(filename)
Dim fileInformation As FileCreationInformation
Dim item As ListItem
Dim library As List = ctx.Web.Lists.GetByTitle(docLibrary)
ctx.Load(library, Function(x) x.RootFolder.ServerRelativeUrl)
ctx.ExecuteQuery()
fileInformation = New FileCreationInformation
With fileInformation
.Url = library.RootFolder.ServerRelativeUrl & "/" & Filename
.Overwrite = True
.Content = System.IO.File.ReadAllBytes(newFilename)
End With
Dim fs As IO.FileStream = New IO.FileStream(newFilename, IO.FileMode.Open)
Dim flciNewFile As FileCreationInformation = New FileCreationInformation()
flciNewFile.ContentStream = fs
flciNewFile.Url = System.IO.Path.GetFileName(newFilename)
flciNewFile.Overwrite = True
Dim docs As List = ctx.Web.Lists.GetByTitle(docLibrary)
Dim uploadFile As Microsoft.SharePoint.Client.File = docs.RootFolder.Files.Add(flciNewFile)
item = uploadFile.ListItemAllFields
item("ColumnA") = "some metadata"
item("ColumnB") = "some metadata"
item.Update()
ctx.Load(uploadFile)
ctx.ExecuteQuery()
答案 0 :(得分:1)
这是新上传的文件项的ID:
uploadFile.ListItemAllFields.Id
已更新:
请按如下所示在ClientContext中加载uploadFile.ListItemAllField:
item = uploadFile.ListItemAllFields
ctx.Load(item)
ctx.ExecuteQuery()
答案 1 :(得分:1)
这可以完成工作:
ctx.Load(uploadFile, Function(f) f.ListItemAllFields)
ctx.ExecuteQuery()
MsgBox(uploadFile.ListItemAllFields.Id)