Skip to main content
Updated info (issue also happens with .ade files)
Source Link

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

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

Source Link

Unable to add .exe file to SharePoint 2010 using Client Object model after it has been removed from blocked files list

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;

                            stream.CopyTo(requestStream);

                            // Try and free up the source stream early doors before potentially long request is sent
                            stream.Dispose();

                            requestStream.Flush();
                            requestStream.Close();
                        }

Regards,

Mark