将图像插入图像库不会返回已创建项目的ID [英] Insertion of image into image library does not return Id of created item
问题描述
嗨!我通过C#CSOM从Web应用程序将新图像插入SharePoint Online图像库。
问题是我没有得到新插入项目的ID。似乎有某种时间在图像库中可用之前,因此ID不可用。
任何想法如何求解这个?
private static int SaveFileToSharePoint(List list,string url,Stream contentStream,IDictionary< string,object> itemProperties)
{
var ctx = list.Context;
contentStream.Position = 0;
var fileInfo = new FileCreationInformation
{
ContentStream = contentStream,
Url = url,&
Overwrite = true
}; b $ b var file = list.RootFolder.Files.Add(fileInfo); // 1。准备添加文件
var item = file.ListItemAllFields;
foreach(varPro in itemProperties)
item [p.Key] = p.Value;
item.Update();&NBSP; // 2。准备列表项目以更新
ctx.Load(item);
ctx.ExecuteQueryRetryAsync();&NBSP; // 3。向服务器提交请求,包括添加文件和更新关联的列表项属性。
return item.Id;
$
}
您好
尝试使用ctx.ExecuteQuery();
Hi! Im inserting a new image into a SharePoint Online image library via C# CSOM from a web application.
The problem is that I do not get the Id of the newly inserted item back. There seems to be some kind of time Before the image is available in the library and therefore is the Id not availible.
Any idea how to solve this?
private static int SaveFileToSharePoint(List list, string url, Stream contentStream, IDictionary<string, object> itemProperties)
{
var ctx = list.Context;
contentStream.Position = 0;
var fileInfo = new FileCreationInformation
{
ContentStream = contentStream,
Url = url,
Overwrite = true
};
var file = list.RootFolder.Files.Add(fileInfo); //1. prepare to add file
var item = file.ListItemAllFields;
foreach (var p in itemProperties)
item[p.Key] = p.Value;
item.Update(); //2. prepare list item to update
ctx.Load(item);
ctx.ExecuteQueryRetryAsync(); //3. submit request to the server that includes adding the file and updading the associated list item properties.
return item.Id;
}
Hi
Try to use ctx.ExecuteQuery();
这篇关于将图像插入图像库不会返回已创建项目的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!