1. 新建一个C#的Console project.
2. 给project 添加reference:
3. 修改project的属性:
4. 修改代码如下:
using System; using System.IO; using System.Net; using Microsoft.SharePoint.Client; namespace ClientUploadTest { class Program { static void Main(string[] args) { ClientContext ctx = new ClientContext("http://mysp2013/sites/sc19/"); ctx.Credentials = new NetworkCredential("administrator", "Password", "mydomain"); using (FileStream fs = new FileStream(@"C:\temp\doc1.docx", FileMode.Open)) { Microsoft.SharePoint.Client.File.SaveBinaryDirect(ctx, @"/sites/sc19/site1/mydoclib/doc1.docx", fs, true); } Console.WriteLine("Uploaded File Successfully"); } } }
5. 运行成功.
后记
==================
一定要确保文件上传的目标地址的正确: URL正确, 文件夹的确存在.
否则会报HTTP 409 Conflict的.
为了避免HTTP 409, 你还需要注意我这个例子中使用的URL:
Happy Coding SharePoint!
参考资料
====================
Upload a document to a SharePoint list from Managed Client Side Object Model
ClientContext error 409! HELP!
http://go4answers.webhost4life.com/Example/clientcontext-error-409-help-90813.aspx
记一个使用Client Object Model上传文件的小例子,布布扣,bubuko.com
记一个使用Client Object Model上传文件的小例子
原文:http://www.cnblogs.com/awpatp/p/3782422.html