Load XML file stream in Xrrichtext

Asked

Viewed 114 times

5

In my application, I receive a array of bytes file XML. With it I create a stream, but when I try to load it and insert it into XRRichText, nothing happens. However, the stream on a user’s computer disk file, when loading the file and inserting the contents into the component, it works perfectly. Even so, I need it to be uploaded through the stream, not from a file.

The code below works, but I can’t use it because of creating files on the user’s computer:

RichEditDocumentServer server = new RichEditDocumentServer();

using (Stream file = File.OpenWrite(@"C:\temp\intro.xml"))
{
    file.Write(pDados.ByteXML, 0, pDados.ByteXML.Length);
} 
server.LoadDocument(@"C:\temp\intro.xml");

...

XRRichText x = (XRRichText)xrCont;
x.Rtf = server.RtfText;

The code below does not work, but it is how I need to do, through the stream, without creating files:

RichEditDocumentServer server = new RichEditDocumentServer();

MemoryStream stream = new MemoryStream();
stream.Write(pDados.ByteXML, 0, pDados.ByteXML.Length);
stream.Flush();
stream.Position = 0;
server.LoadDocument(stream, DocumentFormat.OpenXml);

...

XRRichText x = (XRRichText)xrCont;
x.Rtf = server.RtfText;
  • from what I understand, you load the xml in RichEditDocumentServer and then takes his RTF to play XRRichText... right ?

  • Yes, @Rovannlinhalis, but I imagine that has nothing to do with the problem, since it works when I upload the file. The problem is time to load the stream...

1 answer

1

Use a Binary Writer as the method MemoryStream.Flush() performs no action(https://docs.microsoft.com/.../system.io.memorystream.flush)

RichEditDocumentServer server = new RichEditDocumentServer();

//Cria um BinaryWriter sobre um MemoryStream usando usando a codificação UTF-8.
BinaryWriter writer = new BinaryWriter(new MemoryStream());

//Envia os dados para MemoryStream.
writer.Write(pDados.ByteXML);
writer.Flush(); 


server.LoadDocument(writer.BaseStream , DocumentFormat.OpenXml);

...

XRRichText x = (XRRichText)xrCont;
x.Rtf = server.RtfText;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.