将图像上传到 SharePoint 文档库 C#
Uploading Image into SharePoint document library C#
我有一个当前传递 base64 图像格式的 Web 服务,但是,如何将它插入到共享点库中?我应该将它转换为字节数组吗?
是的,需要读取图像文件流然后使用Microsoft.SharePoint.Client.File.SaveBinaryDirect保存到SharePoint库中:
var fileName=@"C:\Test.jpg";
using (ClientContext context = new ClientContext("http://sp/"))
{
using (var fs = new FileStream(fileName, FileMode.Open))
{
var fi = new FileInfo(fileName);
var list = context.Web.Lists.GetByTitle("Documents");
context.Load(list.RootFolder);
context.ExecuteQuery();
var fileUrl = String.Format("{0}/{1}", list.RootFolder.ServerRelativeUrl, fi.Name);
Microsoft.SharePoint.Client.File.SaveBinaryDirect(context, fileUrl, fs, true);
}
}
这里有一个类似的帖子供您参考:
How to Upload Images to SharePoint Online(Office 365) Picture-library using CSOM (Java Script)?
我有一个当前传递 base64 图像格式的 Web 服务,但是,如何将它插入到共享点库中?我应该将它转换为字节数组吗?
是的,需要读取图像文件流然后使用Microsoft.SharePoint.Client.File.SaveBinaryDirect保存到SharePoint库中:
var fileName=@"C:\Test.jpg";
using (ClientContext context = new ClientContext("http://sp/"))
{
using (var fs = new FileStream(fileName, FileMode.Open))
{
var fi = new FileInfo(fileName);
var list = context.Web.Lists.GetByTitle("Documents");
context.Load(list.RootFolder);
context.ExecuteQuery();
var fileUrl = String.Format("{0}/{1}", list.RootFolder.ServerRelativeUrl, fi.Name);
Microsoft.SharePoint.Client.File.SaveBinaryDirect(context, fileUrl, fs, true);
}
}
这里有一个类似的帖子供您参考:
How to Upload Images to SharePoint Online(Office 365) Picture-library using CSOM (Java Script)?