Я хочу добавить контент в существующий файл в sharepoint. Я использую следующий код:
using Microsoft.Azure.ActiveDirectory.GraphClient;
using Microsoft.SharePoint.Client;
using MSharp.Framework.Services;
using System;
using System.IO;
using System.Net;
using System.Security;
namespace SharepointFileSend
{
class Program
{
private const string V = "XXXXX";
private static string hostWeb="XXXXX.sharepoint.com";
static void Main(string[] args)
{
string siteUrl = "https://XXXXX.sharepoint.com/site/";
string password = "XXX";
//Insert Credentials
ClientContext context = new ClientContext(siteUrl);
var securePassword = new SecureString();
foreach (var c in password.ToCharArray() ) securePassword.AppendChar(c);
context.Credentials = new SharePointOnlineCredentials("XXXX@XXXXX.com", securePassword);
Web site = context.Web;
//Get the required RootFolder
string barRootFolderRelativeUrl = "Documents/Demo";
Folder barFolder = site.GetFolderByServerRelativeUrl(barRootFolderRelativeUrl);
//Create new subFolder to load files into
string newFolderName = "SPTest";
barFolder.Folders.Add(newFolderName);
barFolder.Update();
//Add file to new Folder
Folder currentRunFolder = site.GetFolderByServerRelativeUrl(barRootFolderRelativeUrl + "/" + newFolderName);
string sharePointDocPath = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory.ToString(), "Sharepoint.xml");
FileCreationInformation newFile = new FileCreationInformation { Content = System.IO.File.ReadAllBytes(sharePointDocPath), Url = Path.GetFileName(sharePointDocPath), Overwrite = true };
currentRunFolder.Files.Add(newFile);
currentRunFolder.Update();
context.ExecuteQuery();
//Return the URL of the new uploaded file
// string newUrl = siteUrl + barRootFolderRelativeUrl + "/" + newFolderName + "/" + Path.GetFileName(@p);
}
}
}
Я получаю исключение при последнем утверждении:
context.ExecuteQuery ();
System. Net .WebException: ' Удаленный сервер возвратил ошибку: (400) Bad Request. '
Помогите, пожалуйста, разрешить это исключение, а также добавить содержимое в существующий файл sharepoint.