Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / How to read XML data f...
Finance forum
Unanswered

How to read XML data from MemoryStream

Posted on by 6,316
Hello,
 
I'm trying to read the XML content from the memory stream.
 
Below is the code I tried, but xmlStr remains empty.
_stream is System.IO.MemoryStream, which has come from "ERDocuManagementAttachingFileEventArgs _args" >> _args.getStream();
 
Which has been resolved, but since the subject is now XML, I'm creating this new Post.
 
 
My current code:
str xmlStr;
System.IO.StreamReader  sreader = new System.IO.StreamReader(_stream, System.Text.Encoding::UTF8, true);
xmlStr = sreader.ReadToEnd();
These are the Setup of Document type I use for ER generation
 
  • Anton Venter Profile Picture
    Anton Venter 9,453 Super User on at
    How to read XML data from MemoryStream
    Hello,
     
    If the stream offset is at the end, it will return nothing as in your case. You have to set the offset to the beginning again. I make a copy of the stream in this example below so not to interfere with the standard process.
     
    System.IO.MemoryStream streamArchive = _args.getStream();
    
    if (streamArchive.CanSeek)
    {
        streamArchive.Seek(0, System.IO.SeekOrigin::Begin); //avent: set stream position to 0 so we can read/copy it.
    }
    
    streamArchive.CopyTo(stream);
     
     

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,835 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,526 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans