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