Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

How to read XML data from MemoryStream

(2) ShareShare
ReportReport
Posted on by 6,455
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
    19,607 Super User 2025 Season 1 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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,217 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,976 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans