0

I use this code to upload pdf files to sharepoint in my WinForm application. it works. when I click it try to open in sharepoint, I got this "The document could not be opened for editing. A Windows SharePoint Services compatible application could not be found to edit the document" If I upload manually, click opens fine.

Here is the code:

            FileStream fStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fStream);

            byte[] bytes = br.ReadBytes((int)numBytes);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.ContentType = "application/pdf";
            request.Credentials = CredentialCache.DefaultCredentials; 
            request.Method = "PUT";
            byte[] buffer = new byte[1024];
            using (Stream stream = request.GetRequestStream())
            using (MemoryStream ms = new MemoryStream(bytes))
                for (int i = ms.Read(buffer, 0, buffer.Length); i > 0; i = ms.Read(buffer, 0, buffer.Length))
                    stream.Write(buffer, 0, i);
            WebResponse response = request.GetResponse();
            response.Close();
weslleywang
  • 569
  • 2
  • 8
  • 21
  • Double click? There is no double click in the web. Also: I don't see any SharePoint related methods in your code like `MyLibrary.Files.Add(filename,filestream,true)` – Dennis G Jun 15 '13 at 09:04
  • hi moontear, I change the content to make it clear. – weslleywang Jun 15 '13 at 13:08

0 Answers0