upload documents using COM in sharepoint 2010
-
2012年6月27日 21:19
Hello all.
can you please advise the source code as how to upload a document using Client object model in sharepoint 2010,
many thanks
Kajal
全部回复
-
2012年6月27日 22:03版主
Hi you can use a MemoryStream and the FileCreationInformation class for this: This sample creates a doc library and adds a file to it
using (ClientContext ctx = new ClientContext("your site url")) { Web site = ctx.Web; ctx.Load(site); ctx.ExecuteQuery(); ListCreationInformation listCI = new ListCreationInformation(); listCI.Title = "MyDocs"; listCI.Description = "A document library"; listCI.TemplateType = (int)ListTemplateType.DocumentLibrary; //Create document MemoryStream m = new MemoryStream; StreamWriter w = new StreamWriter(m); w.Write("Hello World from a Document"); w.Flush; FileCreationInformation fileCI = new FileCreationInformation(); fileCI.Content = m.ToArray; fileCI.Overwrite = true; fileCI.Url = "http://<yoursiteurl>/MyDocs/MyFile.txt"; Folder rootFolder = site.GetFolderByServerRelativeUrl("MyDocs"); ctx.Load(rootFolder); Microsoft.SharePoint.Client.File newFile = rootFolder.Files.Add(fileCI); ctx.ExecuteQuery();
}
Kind Regards Bjoern
Blog
- 已编辑 Bjoern H RappMicrosoft Community Contributor, Moderator 2012年6月27日 22:07
- 已编辑 Bjoern H RappMicrosoft Community Contributor, Moderator 2012年6月27日 22:10
- 已编辑 Bjoern H RappMicrosoft Community Contributor, Moderator 2012年6月27日 22:11
- 已编辑 Bjoern H RappMicrosoft Community Contributor, Moderator 2012年6月27日 22:11
- 已编辑 Bjoern H RappMicrosoft Community Contributor, Moderator 2012年6月27日 22:12
- 已编辑 Bjoern H RappMicrosoft Community Contributor, Moderator 2012年6月27日 22:13
- 已编辑 Bjoern H RappMicrosoft Community Contributor, Moderator 2012年6月27日 22:14
- 已编辑 Bjoern H RappMicrosoft Community Contributor, Moderator 2012年6月27日 22:24
- 已编辑 Bjoern H RappMicrosoft Community Contributor, Moderator 2012年6月27日 22:24
- 已标记为答案 kajal mishra 2012年6月28日 4:22
-
2012年6月28日 4:23thanks Bjoern for your help !

