Uploading file in sharepoint library throws an unhandled exception(hresult: 0x80020009, errorcode: -2147352567) with empty error message

3

I m using following code sample to upload multiple files (using sharepoint Object Model, no webservice) in a document library, but some times it throws exception hresult: 0x80020009, with error code -2147352567 and error message is empty (empty string) while file is upload successfully to the document library. And mostly it occurs only first time mean it occurs when uploading first document after that all process goes smoothly no exception occurs after first time occured. If i eat that exception it works fine. Can any one help me to trace the problem, I can't understand why it throws exception while file has been uploaded to document library. I want to know What's the actual reason and what should I do to avoid that problem.

Code: .....

SPFolder folder = web.GetFolder(folderUrl);
foreach(.....)
{
folder.Files.Add(folderUrl + "/" + fileName, file.Data, true);
}
sharepoint
file
exception
upload
asked on Stack Overflow Jan 3, 2011 by Alex • edited Jan 3, 2011 by Ashutosh Singh-MVP SharePoint

1 Answer

1

try using the code provided below that will help you out

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(); 
            }
        }

User contributions licensed under CC BY-SA 3.0