3

I currently have a Desktop application that is able to upload a file to the root directory of my "Documents" Document Library on the Sharepoint Site I am using.

This is done with the following code;

    Dim context As New ClientContext(serviceSiteUrl)
    context.Credentials = GetCredentials()
    Dim web = context.Web
    Dim newFile = new FileCreationInformation
    newFile.Content = IO.File.ReadAllBytes(destination)
    newFile.Url = Path.GetFileName(destination)

    Dim docs = web.Lists.GetByTitle("Documents")
    docs.RootFolder.Files.Add(newFile)
    context.ExecuteQuery()
    Console.WriteLine("File uploaded")
    context.Dispose()

My question is; How am I able to get this application to navigate instead to one of the folders that is currently present within the document library? Currently, the files being uploaded are within the same directory as the folders i'd like them to be within.

0

Provide the sub folder url in the sample code below and then file will be uploaded to the sub folder instead of the root:

ClientContext context = new ClientContext("http://MySiteUrl");
using (FileStream fs = new FileStream(@"x:\MyFile.docx", FileMode.Open))
{
   Microsoft.SharePoint.Client.File.SaveBinaryDirect(context, "/MyLibName/MyFolderName/MyFile.docx", fs, true);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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