I opened existing word document using openxml. Now i need to upload the same document into Document library with memory stream. If i did so my content controls inside the word document gets disappeared. How to resolve this issue?


if SharePoint 2010 or 2013 you can use the File.SaveBinaryDirect method available on the client-side object model. Sample code:

            using (ClientContext clientContext = new ClientContext(docLibUri))
                clientContext.AuthenticationMode = ClientAuthenticationMode.Default;

                // Getting stream from SQL Server
                GetStreamFromSQLServer(pFileStreamId, ref reader, ref stream, ref fileName);

                if (stream == null)
                    throw new Exception("Stream cannot be null");

                if (fileName == null)
                    throw new Exception("Filename cannot be null");

                // Full file path
                String filePath = String.Format("{0}/{1}", docLibRelativePath, fileName);

                // Uploading stream to Document Library
                Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, filePath, stream, true);

| improve this answer | |
  • File gets uploaded, but changes in content control is not reflected. I searched and found we need to update customxmlpart while updating content control value. But i don't know how to update single value in customxmlpart. – Suren Jun 19 '13 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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