title: Core.LargeFileUpload File Not Found Cant find Folder
body: <p>I am trying to upload files larger than 2MB to SharePoint365 using <code>Core.LargeFileUpload</code>.</p>
  
  <p>I have altered it to suit my code but it fails to find my Folder. I get an error response '<code>File Not Found</code>' and a 0 byte file is written to the list </p>
  
  <p>I have tried using : </p>
  
  <pre><code>Folder folder = docs.RootFolder.Folders.GetByUrl(vFolder);
  </code></pre>
  
  <p>to no avail, best I get is a 0 byte file in the folder I want but the error is still "File Not Found"</p>
  
  <pre><code>using Microsoft.SharePoint.Client;
  using System;
  using System.Collections;
  using System.Collections.Generic;
  using System.IO;
  using System.Linq;
  using System.Security;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace UploadSH365
  {
  
      public class FileUploadService
      {
          public string Upload(string vURL, out string vURLout, string vUName, string vPWD, string vList, string vFolder, string vFileName, byte[] vAttachment, Dictionary&lt;string, string&gt; metadata, bool overwrite)
          {       
              string strMsg = "";
              vURLout = "";
              if (string.IsNullOrEmpty(vURL))
  
                  return "Empty URL field";
              int blockSize = 1 * 1024 * 1024;
              try
              {
                  long fileSize = vAttachment.Length;
                //  Microsoft.SharePoint.Client.File uploadFile;
                  Guid uploadId = Guid.NewGuid();
  
                  // Ensure that target library exists, create if is missing
  
                  using (ClientContext clientContext = new ClientContext(vURL))
                       {                     
                      SecureString passWord = new SecureString();
                           foreach (char c in vPWD.ToCharArray()) passWord.AppendChar(c);
                           clientContext.Credentials = new SharePointOnlineCredentials(vUName, passWord);
                           Web web = clientContext.Web;
  
  
                      List docs = clientContext.Web.Lists.GetByTitle(vList);
                      clientContext.Load(docs, l =&gt; l.RootFolder);
                      // Get the information about the folder that will hold the file
                      clientContext.Load(docs.RootFolder, f =&gt; f.ServerRelativeUrl);
                      clientContext.ExecuteQuery();
  
                      // File object 
                      Microsoft.SharePoint.Client.File uploadFile;
  
                      // Calculate block size in bytes
                      // int blockSize = fileChunkSizeInMB * 1024 * 1024;
  
                      // Get the information about the folder that will hold the file
                      clientContext.Load(docs.RootFolder, f =&gt; f.ServerRelativeUrl);
                      clientContext.ExecuteQuery();
                      ;           
                      // Use large file upload approach
                      ClientResult&lt;long&gt; bytesUploaded = null;
  
                           Stream fs = null;
                           try
                           {
  
  
                          fs = new MemoryStream(vAttachment);
                          using (BinaryReader br = new BinaryReader(fs))
                          {
                              byte[] buffer = new byte[blockSize];
                              Byte[] lastBuffer = null;
                              long fileoffset = 0;
                              long totalBytesRead = 0;
                              int bytesRead;
                              bool first = true;
                              bool last = false;
  
                              // Read data from filesystem in blocks 
                              while ((bytesRead = br.Read(buffer, 0, buffer.Length)) &gt; 0)
                              {
                                  totalBytesRead = totalBytesRead + bytesRead;
  
                                  // We've reached the end of the file
                                  if (totalBytesRead == fileSize)
                                  {
                                      last = true;
                                      // Copy to a new buffer that has the correct size
                                      lastBuffer = new byte[bytesRead];
                                      Array.Copy(buffer, 0, lastBuffer, 0, bytesRead);
                                  }
  
                                  if (first)
                                  {
                                      using (MemoryStream contentStream = new MemoryStream())
                                      {
                                          // Add an empty file.
                                          FileCreationInformation fileInfo = new FileCreationInformation();
                                          fileInfo.ContentStream = contentStream;
                                          fileInfo.Url = vFileName;
                                          fileInfo.Overwrite = true;
                                          uploadFile = docs.RootFolder.Files.Add(fileInfo);
  
                                          // Start upload by uploading the first slice. 
                                          using (MemoryStream s = new MemoryStream(buffer))
                                          {
                                              // Call the start upload method on the first slice
                                              bytesUploaded = uploadFile.StartUpload(uploadId, s);
                                              clientContext.ExecuteQuery();
                                              // fileoffset is the pointer where the next slice will be added
                                              fileoffset = bytesUploaded.Value;
                                          }
  
                                          // we can only start the upload once
                                          first = false;
                                      }
                                  }
                                  else
                                  {
                                      // Get a reference to our file
                                      uploadFile = clientContext.Web.GetFileByServerRelativeUrl(docs.RootFolder.ServerRelativeUrl + vFileName);
  
                                      if (last)
                                      {
                                          // Is this the last slice of data?
                                          using (MemoryStream s = new MemoryStream(lastBuffer))
                                          {
                                              // End sliced upload by calling FinishUpload
                                              uploadFile = uploadFile.FinishUpload(uploadId, fileoffset, s);
                                              clientContext.ExecuteQuery();
                                              vURLout = vURL + "/" + vList + "/" + vFolder + "/" + vFileName;
                                              // return the file object for the uploaded file
                                              return vURLout;
                                          }
                                      }
                                      else
                                      {
                                          using (MemoryStream s = new MemoryStream(buffer))
                                          {
                                              // Continue sliced upload
                                              bytesUploaded = uploadFile.ContinueUpload(uploadId, fileoffset, s);
                                              clientContext.ExecuteQuery();
                                              // update fileoffset for the next slice
                                              fileoffset = bytesUploaded.Value;
                                          }
                                      }
                                  }
  
                              } // while ((bytesRead = br.Read(buffer, 0, buffer.Length)) &gt; 0)
                          }    
                      }
                      finally
                           {
                               if (fs != null)
                               {
                                   fs.Dispose();
                               }
                           }    
                       }                                                 
              }
              catch (Exception ex)
              {
                  strMsg = ex.Message;
              }
  
              return strMsg;
              // Console.ReadLine();
          }
      }
  }
  </code></pre>
  
  <p>0 Byte File is written to the List instead of the Folder I want.</p>