Language: C# Framework: .Net 4.5.1 Environment: SharePoint 2010 - Windows Server 2008 R2

My software is used to upload files to sharepoint. It works perfectly well for the majority of files. However, files on the "Blocked File List" throw an error when trying to upload (404 Not Found) as is expected. However, once you remove the file from the Blocked file list in Central Admin (and the XML doc in Program Files > Shared Docs...) you can manually upload through the interface, but the upload using code still fails.

If you manually upload a file (.exe in this case) and click on it, you do get a 404, however you are still able to right click and "Download a copy" and view the file in the interface.

I assume this 404 is what is causing the upload to fail. Is there any way around this? I have restarted the machine and IIS since changing the file type but that had no effect.

using (WebClient client = this.GetWebClient(stream.Length))
                        client.Headers.Add("User-Agent", USER_AGENT);
                        client.Headers.Add("Accept-Language", "en-us");
                        client.Headers.Add("Translate", "F");
                        client.Headers.Add("Cache-Control", "no-cache");

                        using (Stream requestStream = client.OpenWrite(destinationUri, WebRequestMethods.Http.Put))
                            requestStream.ReadTimeout = Timeout.Infinite;
                            requestStream.WriteTimeout = Timeout.Infinite;


                            // Try and free up the source stream early doors before potentially long request is sent




UPDATE: The is also happening for .ADE files. So it may be for any "Blocked File" that is removed from the list.

1 Answer 1


Use CSOM to Upload the file:

 1: ClientContext context = new ClientContext("http://spdevinwin");
   3: Web web = context.Web;
   5: FileCreationInformation newFile = new FileCreationInformation();
   6: newFile.Content = System.IO.File.ReadAllBytes(@"C:\Work\Files\17580_FAST2010_S05_Administration.pptx");
   7: newFile.Url = "17580_FAST2010_S05_Administration 4MB file uploaded via client OM.pptx";
   9: List docs = web.Lists.GetByTitle("Documents");
  10: Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);
  11: context.Load(uploadFile);
  12: context.ExecuteQuery();
  13: Console.WriteLine("done");

You can also try : Go into IIS (I am assuming IIS 7.0) and select the particular web site and click handler mappings and Edit feature permissions and uncheck the Execute box

  • Fantastic. I never thought about the IIS setting. Great catch. Many thanks. Now I just have to explain to customers why it's a bad idea to upload exes to SharePoint Jun 15, 2014 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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