web
You’re offline. This is a read only version of the page.
close
Skip to main content
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,470
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
 
I have the same question (0)
  • Anton Venter Profile Picture
    20,219 Super User 2025 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 764 User Group Leader

#2
Martin Dráb Profile Picture

Martin Dráb 619 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 603 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans