web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

how assign string value to stream by code x++

(0) ShareShare
ReportReport
Posted on by 45

Hello exports,

when i try to assign string value to stream, i get the error of data convert :

Cannot  implicitly convert from type 'str' to type 'System.IO.Stream'

pastedimage1628504047771v1.png

How i can resolve the problem please ?

Thanks

I have the same question (0)
  • Suggested answer
    ergun sahin Profile Picture
    8,826 Moderator on at

    System.Byte[] byteArray = System.Text.Encoding::get_UTF8().GetBytes(contents);
    System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);

    Note: You can find the original at the link below. I wrote it in the Editor for X . There may be minor differences.

    stackoverflow.com/.../convert-string-to-system-io-stream

  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    By the way, the variable name (invoicePath) suggests that it contains just a path, not the content of the file. Are you sure that what you want to attach is just the text with the path? If you want to attach the whole file, you need to read it from the path (and assign the content, not the path, to the 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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans