我需要从文件库创建/添加新文件,然后需要使用唯一ID设置文件名并更新其他文件。我可以毫无问题地更新字段,但找不到创建文件的方法。
我怎么可能实现New =>从模板创建(如下图所示)
我尝试了很多方法,但是没有什么可以满足我的要求。
this.web.lists.getByTitle('myFilesLib')。items.add()=>我收到有关需要使用SPFileCollection.Add()的错误
this.web.getFolderByServerRelativeUrl(url).files.addTemplateFile =>自定义模板没有任何内容
this.web.getFolderByServerRelativeUrl(url).files.add =>我需要提供一个文件。
答案 0 :(得分:0)
对于JSOM,您可以尝试以下操作:
newFile = parentList.get_rootFolder()。get_files()。add(fileCreateInfo);
对于CSOM:
StoredProcedure
http://www.ktskumar.com/2016/08/pnp-js-core-create-new-page-sharepoint-library/
Microsoft提供的更多参考资料: https://msdn.microsoft.com/en-us/library/office/dn450841.aspx
答案 1 :(得分:0)
这是当您要将现有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