C# 使用C将文件上载到sharepoint中的文件夹#

C# 使用C将文件上载到sharepoint中的文件夹#,c#,sharepoint,upload,directory,C#,Sharepoint,Upload,Directory,我尝试将文件上载到sharepoint中的文件夹(而不是列表)。但是,“executeQuery()”何时显示错误“未找到文件”:s 我尝试了很多东西,最后一个是: string siteUrl = "https://xxx.sharepoint.com/sites/some/some2"; //Insert Credentials ClientContext context = new ClientContext(siteUrl); Secur

我尝试将文件上载到sharepoint中的文件夹(而不是列表)。但是,“executeQuery()”何时显示错误“未找到文件”:s

我尝试了很多东西,最后一个是:

string siteUrl = "https://xxx.sharepoint.com/sites/some/some2";
        //Insert Credentials
        ClientContext context = new ClientContext(siteUrl);

        SecureString passWord = new SecureString();
        foreach (var c in "MySecurityPassword.") passWord.AppendChar(c);
        context.Credentials = new SharePointOnlineCredentials("name@domain.com", passWord);
        Web site = context.Web;

        //Get the required RootFolder
        string barRootFolderRelativeUrl = "2017"; //<- existent folder
        Folder barFolder = site.GetFolderByServerRelativeUrl(barRootFolderRelativeUrl);

        //Create new subFolder to load files into
        string newFolderName = "pro" + DateTime.Now.ToString("yyyyMMddHHmm");
        barFolder.Folders.Add(newFolderName);
        barFolder.Update();

        //Add file to new Folder
        Folder currentRunFolder = site.GetFolderByServerRelativeUrl(barRootFolderRelativeUrl + "/" + newFolderName);
        FileCreationInformation newFile = new FileCreationInformation { Content = System.IO.File.ReadAllBytes(@p), Url = Path.GetFileName(@p), Overwrite = true };
        currentRunFolder.Files.Add(newFile);
        currentRunFolder.Update();

        context.ExecuteQuery();

        //Return the URL of the new uploaded file
        newUrl = siteUrl + barRootFolderRelativeUrl + "/" + newFolderName + "/" + Path.GetFileName(@p);
string siteUrl=”https://xxx.sharepoint.com/sites/some/some2";
//插入凭据
ClientContext=新的ClientContext(siteUrl);
SecureString密码=新SecureString();
foreach(MySecurityPassword中的var c)passWord.AppendChar(c);
context.Credentials=新的SharePointOnlineCredentials(“name@domain.com“,密码);
Web站点=context.Web;
//获取所需的根文件夹

字符串barRootFolderRelativeUrl=“2017”// 我对自己说:

问题是中的“url”参数

需要是网站的相对URL。虽然是用“”定义的完整url,但有必要在中定义“/sites/some/some2”作为相对url

FileCreationInformation newFile = new FileCreationInformation { Content = System.IO.File.ReadAllBytes(@p), Url = "/sites/some/some2/"+fileName, Overwrite = true };
还有工作。(微软,干得好)

FileCreationInformation newFile = new FileCreationInformation { Content = System.IO.File.ReadAllBytes(@p), Url = "/sites/some/some2/"+fileName, Overwrite = true };