none
File Not Found error message while uploading document into sharepoint online using Client SDK RRS feed

  • Question

  • Hi,

    I'm getting "File Not Found" error message when I try to upload a file into SharePoint Online using Client SDK with below code. The same code was working till now and suddenly I'm started getting this error message.

    I'm able to upload the file using this code in another document library on the same site but getting this error only on a specific document library. Also, I'm able to upload the file manually to this document library but this error is occurring only when I upload using the code.

    Please suggest if you have any inputs on this issue. Thanks in advance.

     using (ClientContext context = GetContextObject())
                    {
                        using (FileStream fs = new FileStream(@"E:\Test\Test.pdf", FileMode.Open))
                        {
                            Web web = context.Web;
                            FileCreationInformation newFile = new FileCreationInformation();
                            newFile.ContentStream = fs;
                            newFile.Url = "Test.pdf";
                            newFile.Overwrite = true;
                            var targetFolder = context.Web.GetFolderByServerRelativeUrl(_SPRoot + "/" + _folder);
                            var uploadFile = targetFolder.Files.Add(newFile);
                            context.Load(uploadFile);
                            context.ExecuteQuery();
                        }
                    }

    Regards

    Gopi






    • Edited by MSR Gopi Monday, April 17, 2017 5:36 PM
    Saturday, April 8, 2017 1:52 AM

Answers

  • Update your code as follows

     using (ClientContext context = GetContextObject())
                        {
                            using (FileStream fs = new FileStream(@"E:\Test\Test.pdf", FileMode.Open))
                            {
                                string filePath = _SPRoot + "/" + _folder + "/" + "Test.pdf";
                                File.SaveBinaryDirect(context, filePath, fs, true);
                            }
                        }
    The above snippet is working for SPO site.
    Saturday, April 8, 2017 4:48 AM

All replies

  • Update your code as follows

     using (ClientContext context = GetContextObject())
                        {
                            using (FileStream fs = new FileStream(@"E:\Test\Test.pdf", FileMode.Open))
                            {
                                string filePath = _SPRoot + "/" + _folder + "/" + "Test.pdf";
                                File.SaveBinaryDirect(context, filePath, fs, true);
                            }
                        }
    The above snippet is working for SPO site.
    Saturday, April 8, 2017 4:48 AM
  • Hi Gopi,

    Any progress?

    Best regards,

    Patrick


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, April 13, 2017 3:02 AM
    Moderator
  • Thanks a lot Konjeti. The code that you shared is working fine.

    Regards

    Gopi


    • Edited by MSR Gopi Monday, April 17, 2017 5:36 PM
    Monday, April 17, 2017 5:36 PM