Uploading a file in the sharepoint library raises an unhandled exception (hresult: 0x80020009, error code: -2147352567) with an empty error message

I use the following code example to upload multiple files (using the sharepoint Object Model, no webservice) in the document library, but sometimes it throws an hresult exception: 0x80020009 with error code -2147352567 and the error message is empty (empty line), and the file loads successfully to the document library. And basically this only happens the first time it happens when the first document is loaded after the whole process went smoothly. An exception does not occur after the first time. If I eat this exception, it works fine. Can someone help me track the problem, I can’t understand why it throws an exception when the file is uploaded to the document library. I want to know what the actual reason is and what should I do to avoid this problem.

the code: .....

SPFolder folder = web.GetFolder(folderUrl);
foreach(.....)
{
folder.Files.Add(folderUrl + "/" + fileName, file.Data, true);
}
+3
1

,

using (SPSite spsite = new SPSite("http://SPS01"))
        {
            using (SPWeb spweb = spsite.OpenWeb())
            {
                spweb.AllowUnsafeUpdates = true;

                SPFolder spfolder = spweb.Folders[Site + "/Shared Documents/"];
                byte[] content = null;
                using (FileStream filestream = new FileStream("C:/Sample.docx", System.IO.FileMode.Open))
                {
                    content = new byte[(int)filestream.Length];
                    filestream.Read(content, 0, (int)filestream.Length);
                    filestream.Close();
                }

                SPFile spfile = spfolder.Files.Add("Sample.docx", content, true);

                //Upload file in subfolder.
                //SPFile spfile = spfolder.SubFolders["Demonstration Folder"].Files.Add("Sample.docx", content, true);   
            spfile.Update(); 
            }
        }
+1

Source: https://habr.com/ru/post/1783173/


All Articles