使用 Microsoft.SharePoint.Client 将图像上传到共享点文件夹

Uploading Image using Microsoft.SharePoint.Client to a sharepoint folder

我无法使用 C# 的一半代码将图像上传到共享点文件夹。我可以得到标题,但有什么方法可以上传图片。

actual url to the folder: 

https://mywebsite/sites/COLBMAOpsServ/ip/Forms/AllItems.aspx?id=%2Fsites%2FCOLBMAOpsServ%2Fip%2F01%20Business%20Cases%2FPMO%20Tools%20%26%20Information%2FIPA%20dump%20folder%5FSWP%20images&p=true&originalPath=aHR0cHM6Ly9zcG8uYmhwYmlsbGl0b24uY29tLzpmOi9zL0NPTEJNQU9wc1NlcnYvRW9nVC1hQl83NnBCaEFLYzdnZHlldGtCWnRmaGRZVkUzVHdrdTBFQ1cxLVFLUT9ydGltZT1OWmRmN2J1SDJVZw



public class Program
    {
        static void Main(string[] args)
        {
            string siteUrl = "https://mywebsite/sites/COLBMAOpsServ";
            
            using (var cc = new AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, "4a30b9e9-2222-3333-45678-e59af9bf8150", "QsyzIc09Rt3bBmWk4444444444M5KpLv9LX45678990U="))
            {
                cc.Load(cc.Web, p => p.Title);
                cc.ExecuteQuery();
                Console.WriteLine(cc.Web.Title);
            };
        }
    }

您可以像这样将文件上传到共享点文件夹:

        var uploadFilePath = @"C:\temp\test.jpg";
        var uploadFolderUrl = "/sites/yoursite/Shared%20Documents/folder";
        var fileCreationInfo = new FileCreationInformation
        {
            Content = System.IO.File.ReadAllBytes(uploadFilePath),
            Overwrite = true,
            Url = Path.GetFileName(uploadFilePath)
        };
        var targetFolder = ctx.Web.GetFolderByServerRelativeUrl(uploadFolderUrl);
        var uploadFile = targetFolder.Files.Add(fileCreationInfo);
        ctx.Load(uploadFile);
        ctx.ExecuteQuery();