2

Sharepoint Version: 2016

I have tried many solutions but still am failing. One site which had a possible solution was: http://www.stuartroberts.net/index.php/2014/05/09/sending-large-data-csom/ but when I go to use:

    var fci = new FileCreationInformation
            {
                Url = relativeItemUrl,
                ContentStream = stream,
                Overwrite = true
            };

I end up getting "'FileCreationInformation' does not contain a definition for 'ContentStream'" even though I am using "Microsoft.SharePoint.Client" in my project.

I tried:

    using (FileStream fs = new FileStream(pathToFile, FileMode.Open))
        {
           Microsoft.SharePoint.Client.File.SaveBinaryDirect(context, @"/" + number + @"/" + fileToAdd, fs, true);
        }

which ended up just giving me a conflict error after about 3 minutes.

And then I tried:

   string fileToAdd = Regex.Replace(pathToFile, @"^[^_]*\\", ""); // - UNC

        string cName = number + "-" + name;

        byte[] bytes = System.IO.File.ReadAllBytes(pathToFile); //Loads all of file, needs full path to file here

        FileCreationInformation newFile = new FileCreationInformation();

        ClientContext context = new ClientContext(url);
        context.RequestTimeout = Int32.MaxValue;

        context.Credentials = new NetworkCredential("userName", "password", "domain");
        List uploadFileLocation = context.Web.Lists.GetByTitle(libraryName);
        context.Load(uploadFileLocation.RootFolder);

        newFile.Content = bytes;
        newFile.Content = System.IO.File.ReadAllBytes(pathToFile);

        newFile.Overwrite = true;

        switch (type)
        {
            case "spFolder":
                newFile.Url = url + @"/" + cNumber+ @"/" + Name+ @"/" + fileToAdd;
            break;
            case "spDocLibrary":
                newFile.Url = url + @"/" + cNumber + @"/" + fileToAdd;
            break;
        }

        Microsoft.SharePoint.Client.File uploadFileToSpFolder = uploadFileLocation.RootFolder.Files.Add(newFile);
        //uploadFileToSpFolder.ListItemAllFields["FileLeafRef"] = "Name of file here";

        uploadFileToSpFolder.ListItemAllFields.Update();
        context.RequestTimeout = Int32.MaxValue;
        context.ExecuteQuery();

Which ends up telling me "The file is too long. This operation is currently limited to supporting files less than 2 gigabytes in size."

I've went through many articles about chunking but have had no luck, any suggestions/tips?

Your Answer

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

Browse other questions tagged or ask your own question.