SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm experiencing some problems adding documents to a library using the object model. I use the spfolder.files.add where I pass a filestream containing the document in. When I run my Internet Explorer as administrator, all works fine. When I run it normally it doesn't want to open a filestream to the documents. Any suggestions? I use Kerberos as security protocol. Any suggestions?


share|improve this question
Can you paste the code here please? – Stefano Paterno May 16 '12 at 16:25

Using object model check this code to upload document to document library from local network.

 String fileToUpload = @"C:\YourFile.txt";
    String sharePointSite = "";
    String documentLibraryName = "Shared Documents";

    using (SPSite oSite = new SPSite(sharePointSite))
        using (SPWeb oWeb = oSite.OpenWeb())
            if (!System.IO.File.Exists(fileToUpload))
                throw new FileNotFoundException("File not found.", fileToUpload);                    

            SPFolder myLibrary = oWeb.Folders[documentLibraryName];

            // Prepare to upload
            Boolean replaceExistingFiles = true;
            String fileName = System.IO.Path.GetFileName(fileToUpload);
            FileStream fileStream = File.OpenRead(fileToUpload);

            // Upload document
            SPFile spfile = myLibrary.Files.Add(fileName, fileStream, replaceExistingFiles);

            // Commit 

If you want to upload without permission then put hole code in

    // implementation of full code here
share|improve this answer
Thanks for the reply. I used the same code as you did, but I'll give the RunWithElevatedPrivileges a try – user7531 May 21 '12 at 6:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.