我需要从Files Lib创建/添加一个新文件,然后我需要用唯一的ID设置文件的名称,并更新其他字段。我可以毫无问题地更新字段,但我找不到创建文件的方法。
如何才能实现从模板创建新的=>,如下图所示
我试过很多方法,但都不能满足我的要求。
1
this.web.lists.getByTitle('myFilesLib').items.add() =>我收到一个关于需要使用SPFileCollection.Add()的错误
2
this.web.getFolderByServerRelativeUrl(url).files.addTemplateFile =>没有用于自定义模板的内容
3.
this.web.getFolderByServerRelativeUrl(url).files.add =>我需要提供一个文件。
发布于 2018-08-07 19:03:10
对于
newFile = parentList.get_rootFolder().get_files().add(fileCreateInfo);
对于CSOM:
var creationInformation = new ListItemCreationInformation();
Microsoft.SharePoint.Client.ListItem listItem = list.AddItem(creationInformation);
listItem.FieldValues["Foo"] = "Bar";
listItem.Update();
clientContext.ExecuteQuery();
http://www.ktskumar.com/2016/08/pnp-js-core-create-new-page-sharepoint-library/
更多来自微软的参考资料:https://msdn.microsoft.com/en-us/library/office/dn450841.aspx
发布于 2018-08-08 00:25:51
这是一个示例代码,当您想要将现有的ContentType上载到SharePoint上的内容库时使用。
const templateUrl = '/sites/App/Template/Forms/Template/test.docx'
const name = 'test.docx'
const depositUrl = '/sites/App/Template'
const web = new Web('http://localhost:8080/sites/App'); // Proxy URL for Dev
web.getFileByServerRelativeUrl(templateUrl)
.getBuffer()
.then((templateData: ArrayBuffer) => {
web.getFolderByServerRelativeUrl(depositUrl).files.add(name, templateData));
});
如果您现在使用SP-Rest-Proxy有一个问题(文件在SharePoint上被损坏),但它应该很快就会被修复。
如果你在SharePoint上部署你的应用程序,它会像预期的那样工作。
相关链接:
https://github.com/pnp/pnpjs/issues/196#issuecomment-410908170
https://stackoverflow.com/questions/51712469
复制相似问题