我正在运行一个小代码,以将文件上传到SharePoint 2016文档库中并更改元数据。
有时(但实际上经常),我的代码返回错误消息“在可查询[404]中找不到HttpClient请求时出错”,并显示消息“项目不存在。它可能已被另一个用户删除。”
这是我的代码:
pnp.sp.web.getFolderByServerRelativeUrl("/sites/mysite/ConfigDL").files.add(fileOgg.name, fileOgg, true).then(function (data) {
var RelativeUrls="/sites/mysite/ConfigDL/"+fileOgg.name;
//Retrive Document which is uploaded. Start
pnp.sp.web.getFolderByServerRelativeUrl(RelativeUrls).getItem().then(item => {
//update start Below Call to Doc List will update the Row baseed on Item.ID
pnp.sp.web.lists.getByTitle("ConfigDL").items.getById(item.ID).update({
Number: ""+number+""
}).then(r => {
alert(file.name + " upload successfully!");
});//update end
}); //Retrive Doc Info End
}); //Upload Document End
我不知道为什么会随机发生此错误以及我的代码有什么问题。有什么建议吗?
答案 0 :(得分:0)
在我的SharePoint Online中对测试代码进行采样,它应与SharePoint 2016相同。
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pnp-pnpjs/1.3.4/pnpjs.es5.umd.bundle.min.js"></script>
<script type="text/javascript">
function UpLoadFile() {
var input = document.getElementById("thefileinput");
var fileOgg = input.files[0];
pnp.sp.web.getFolderByServerRelativeUrl("/sites/lee/MyDoc3").files.add(fileOgg.name, fileOgg, true).then(function (data) {
var RelativeUrls = "/sites/lee/MyDoc3/" + fileOgg.name;
//Retrive Document which is uploaded. Start
pnp.sp.web.getFolderByServerRelativeUrl(RelativeUrls).getItem().then(item => {
//update start Below Call to Doc List will update the Row baseed on Item.ID
pnp.sp.web.lists.getByTitle("MyDoc3").items.getById(item.ID).update({
Test: "testvalue"
}).then(r => {
alert(fileOgg.name + " upload successfully!");
});//update end
}); //Retrive Doc Info End
}); //Upload Document End
//pnp.sp.web.getFolderByServerRelativeUrl("/sites/lee/Shared Documents/asd").getItem().then(item => {
// console.log(item);
//});
}
</script>
<input id="thefileinput" type="file" />
<br />
<input id="Button1" onclick="UpLoadFile()" type="button" value="Upload" />