0

我使用此代码将 pdf 文件上传到我的 WinForm 应用程序中的共享点。有用。当我单击它尝试在 sharepoint 中打开时,我得到这个“无法打开文档进行编辑。找不到与 Windows SharePoint Services 兼容的应用程序来编辑文档”如果我手动上传,单击打开正常。

这是代码:

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

0 回答 0