Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Unanswered

How to read XML data from MemoryStream

(2) ShareShare
ReportReport
Posted on by 6,420
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 19,459 Super User 2024 Season 2 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 usually just make a copy of the original stream like 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);
     
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,904 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,605 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans