locked
Add note without temporary folder using Open XML. RRS feed

  • General discussion

  • Hi All,

        public static void HelloWorld(string docName)
            {

                using(var stream = new MemoryStream())
                {
                      using (WordprocessingDocument package = WordprocessingDocument.Create(stream, WordprocessingDocumentType.Document,true))
                      {
                            package.AddMainDocumentPart();

                    // Create the Document DOM.
                    package.MainDocumentPart.Document =
                      new Document(
                        new Body(
                          new Paragraph(
                            new Run(
                              new Text("Hello World!")
                              
                              ))));

                      }
                      stream.Position = 0;
                      byte[] byteData = new byte[stream.Length];
                      stream.Read(byteData, 0, byteData.Length);
                      stream.Close();
                      string encodedData = System.Convert.ToBase64String(byteData);
                  Entity annotation = new Entity("annotation");
                  annotation.Attributes["subject"] = "My subject";
                  annotation.Attributes["notetext"] = "My note text";
                  EntityReference noteRef = new EntityReference();
                  noteRef.LogicalName = "contact";
                  noteRef.Id = new Guid("F70DC04E-2FB1-4C94-A385-A06D344EDC43");
                  annotation["documentbody"] = encodedData;
                  annotation["filename"] = docName;
                  annotation["mimetype"] = @"application\ms-word";
                  annotation.Attributes.Add("objectid", noteRef);
                  annotation.Attributes.Add("objecttypecode", "contact");
                  _serviceProxy.Create(annotation);
                   

                }
            }


    Hope this helps. ----------------------------------------------------------------------- Santosh Bhagat If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    Monday, September 22, 2014 9:41 AM