I'm trying to upload a file to a document set which is located in a library.

Im using C# and the Sharepoint Client Object Model - Library, but I can not find any documentation to do this task.

I know how to upload the file itself to the library's root, but I did not find any possibility to upload it to a document set yet.

Thanks in advance

2 Answers 2


How to upload file into Document Set using SharePoint 2010/2013 CSOM

/// <summary>
/// Upload file into Document Set
/// </summary>
/// <param name="list">List Title</param>
/// <param name="docSetName">DocumentSet Name</param>
/// <param name="fileName">File name to upload</param>
private static void UploadFileIntoDocumentSet(List list,string docSetName, string fileName)
    var ctx = list.Context;
    using (var fs = new FileStream(fileName, FileMode.Open))
        var fi = new FileInfo(fileName);
        var fileUrl = String.Format("{0}/{1}/{2}", list.RootFolder.ServerRelativeUrl,docSetName, fi.Name);
        Microsoft.SharePoint.Client.File.SaveBinaryDirect(ctx, fileUrl, fs, true);


 using (var ctx = new ClientContext(url))
     var list = ctx.Web.Lists.GetByTitle(listTitle);
     UploadFileIntoDocumentSet(list,"Orders", @"C:\Order.docx");

Document sets are somewhat similar to Folders in Document library. In below code we set the path to document set and upload Files to it:

//Declare path to document set
            SPFolder myLibraryToUploadDocument = spWeb.Folders[documentLibraryName].SubFolders[txtTitle.Text];
            // Prepare to upload
            Boolean replaceExistingFiles = true;
            String fileName = System.IO.Path.GetFileName(fullPathFileName);
            FileStream fileStream = File.OpenRead(fullPathFileName);
            // Upload document
            SPFile spfile = myLibraryToUploadDocument.Files.Add(fileName, fileStream, replaceExistingFiles);
            // Commit


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.