C# 使用csom C将图像上载到sharepoint通用列表#
如何使用CSOM C将图像上载到SharePoint列表“自定义列表”而不是库 以下是我迄今为止所尝试的:C# 使用csom C将图像上载到sharepoint通用列表#,c#,.net,sharepoint,csom,C#,.net,Sharepoint,Csom,如何使用CSOM C将图像上载到SharePoint列表“自定义列表”而不是库 以下是我迄今为止所尝试的: FieldUrlValue url = new FieldUrlValue(); url.Url = FileUpload.PostedFile.FileName; url.Description = "Your description here"; newItem["Image"] = url; 您可以使用此代码通过CSOM将文档上载到SharePoint: using (Cli
FieldUrlValue url = new FieldUrlValue();
url.Url = FileUpload.PostedFile.FileName;
url.Description = "Your description here";
newItem["Image"] = url;
您可以使用此代码通过
CSOM
将文档上载到SharePoint
:
using (ClientContext ctx = new ClientContext("http://urlToYourSiteCollection")) {
FileCreationInformation fci = new FileCreationInformation();
fci.Content = System.IO.File.ReadAllBytes("PathToSourceDocument");
fci.Url = System.IO.Path.GetFileName("PathToSourceDocument");
Web web = ctx.Web;
List targetDocLib = ctx.Web.Lists.GetByTitle("yourTargetLibrary");
ctx.ExecuteQuery();
Microsoft.SharePoint.Client.File newFile = targetDocLib.RootFolder.Files.Add(fci);
ctx.Load(newFile);
ctx.ExecuteQuery();
}
如果要设置新项目的属性,可以通过以下方式进行设置:
ListItem lItem = newFile.ListItemAllFields;
lItem.File.CheckOut(); //CHECK OUT VERY IMPORTANT TO CHANGE PROPS
ctx.ExecuteQuery();
lItem["yourProperty"] = "somewhat";
lItem.Update();
lItem.File.CheckIn("Z", CheckinType.OverwriteCheckIn);
ctx.ExecuteQuery();
如果需要将文件上载到SharePoint网站,请访问以下链接,其中说明了如何使用CSOM读取和上载文件
从桌面上载图像时,我出现错误“url无效”。如果使用url(自定义列表中的字段url),则图像必须已位于SharePoint上(并从SharePoint而不是本地计算机设置url)。这就是为什么你有一个错误“URL是无效的”嗨,我尝试了你的代码,它工作得很好,我在图像库中有一个查找字段,我如何设置该值,lItem[“我的查找字段”]=value;不起作用。此解决方案甚至应适用于查找字段。但是我会试着检查一下。谢谢它能工作,
FieldLookupValue lookupf=newfieldlookupvalue();lookupf.LookupId=1;lItem[“Account”]=lookupf代码>