首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PNP-JS从文件库创建文件模板

PNP-JS从文件库创建文件模板
EN

Stack Overflow用户
提问于 2018-08-07 01:01:46
回答 2查看 830关注 0票数 0

我需要从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 =>我需要提供一个文件。

EN

回答 2

Stack Overflow用户

发布于 2018-08-07 19:03:10

对于

  • JSOM,您可以尝试这样做:

newFile = parentList.get_rootFolder().get_files().add(fileCreateInfo);

对于CSOM:

代码语言:javascript
运行
复制
var creationInformation = new ListItemCreationInformation();
Microsoft.SharePoint.Client.ListItem listItem = list.AddItem(creationInformation);
listItem.FieldValues["Foo"] = "Bar";
listItem.Update();
clientContext.ExecuteQuery(); 

用于这种方式的一些维基:https://social.technet.microsoft.com/wiki/contents/articles/37575.sharepoint-online-working-with-files-inside-document-library-using-jsom.aspx

  1. this.web.getFolderByServerRelativeUrl(url).files.addTemplateFile用于添加页面,因此不适合您的方案。

http://www.ktskumar.com/2016/08/pnp-js-core-create-new-page-sharepoint-library/

  1. PnP JS方法需要文件DOM或BLOB对象才能将文件上载到SharePoint。在此基础上,我们将尝试两种方法将文件上传到FileAPI库或库中的文件夹:BLOB/ SharePoint http://www.ktskumar.com/2016/09/pnp-js-core-upload-file-sharepoint/

更多来自微软的参考资料:https://msdn.microsoft.com/en-us/library/office/dn450841.aspx

票数 0
EN

Stack Overflow用户

发布于 2018-08-08 00:25:51

这是一个示例代码,当您想要将现有的ContentType上载到SharePoint上的内容库时使用。

代码语言:javascript
运行
复制
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://github.com/koltyakov/sp-rest-proxy/issues/61

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51712469

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档