Freigeben über


Using the SharePoint 2010 Client OM with Open XML - Uploading a Document

This is a clipboard friendly version of example #3, Uploading a Document, from Using the SharePoint 2010 Managed Client Object Model with Open XML.

This blog is inactive.
New blog: EricWhite.com/blog

Blog TOC

using System;
using System.IO;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using Microsoft.SharePoint.Client;
// The following directive is used to avoid ambiguity between the
// System.IO.File and Microsoft.SharePoint.Client.File classes.
using ClientOM = Microsoft.SharePoint.Client;

class Program
{
static void Main(string[] args)
{
ClientContext clientContext =
new ClientContext("https://intranet.contoso.com");
using (FileStream fileStream =
new FileStream("NewDocument.docx", FileMode.Open))
ClientOM.File.SaveBinaryDirect(clientContext,
"/Shared Documents/NewDocument.docx", fileStream, true);
}
}