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

X++ Write file with hex code NULL

(0) ShareShare
ReportReport
Posted on by 280

Hello,

I want to create a gif-file. I get hex-code from a webservice which I need to convert to a file.
The response from the webservice is for example "474946383961de00de00f00" which I need to write to a .gif file.
When I try the following example, it doesn't return the "00", so when I open the file in an hexeditor I still get "474946383961dedef0".
How can I do that?

static void Job00001(Args _args)
{
    AsciiIO     asciiFile;
    int         i;
    #file
    container   c;
    ;
    c  = "47";
    c  = "49";
    c  = "46";
    c  = "38";
    c  = "39";
    c  = "61";
    c  = "de";
    c  = "00";
    c  = "de";
    c  = "00";
    c  = "f0";
    c  = "00";
    c  = "00";
    c  = "00";
    c  = "00";
    c  = "00";
    c  = "00";
    c  = "ff";
    c  = "ff";
    c  = "ff";
    c  = "2c";
    asciiFile = new asciiIo(@"C:\temp\file.gif", #io_write);
    for (i=1; i<=conlen(c); i =1)
    {
        asciiFile.writeChar(hex2int(conpeek(c, i)));
    }
    info("END");
}

  • Martin Dráb Profile Picture
    Martin Dráb 231,305 Most Valuable Professional on at
    RE: X++ Write file with hex code NULL

    I think it's the consequence of your design. There is no point of physically writing "nothing" to a text file, therefore AsciiIo probably doesn't bother to do that. I fully understand that it makes a difference when writing binary data, but that's not what AsciiIo is for.

    Personally, I would parse the string to System.Byte[] and write this byte array to a file with System.IO.File::File.WriteAllBytes(). AX 4.0 was the first version with CLR Interop, therefore it shouldn't be too difficult. If you go this way, don't forget to explicitly catch CLR exceptions, because they're not shown in infolog automatically.

  • EDV Abteilung Profile Picture
    EDV Abteilung 280 on at
    RE: X++ Write file with hex code NULL

    Yes, it looks crazy :-) but it works, except the conversion of hex2int("00").

    I'll take a look at BinData Class. If you have an example, it would be very helpful.

    The provider don't have a base64 encoding. I don't know why, because all other files from the provider like PDF are transferred as base64

  • Martin Dráb Profile Picture
    Martin Dráb 231,305 Most Valuable Professional on at
    RE: X++ Write file with hex code NULL

    The whole design looks wrong to me. You're not creating a GIF image; you're creating a text file. That the text file has .gif extension doesn't change this fact.

    Do I understand correctly that you receive a string representation of bytes making a GIF file? If there isn't any better function, you'll need to split the string to pieces representing bytes, convert them to actual (numeric) byte values and save these bytes to a file. Check out what you can do with BinData class; I believe it exists in AX 4.0.

    Why doesn't the other side use base64 encoding to convert the file content to text?

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: X++ Write file with hex code NULL

    Perhaps a stupid question, but if you want to open the file in hex editor, shouldn't you store the hex value in the file? Instead of hex2int converted value? What is the purpose of the hex2int conversion?

    Anyway your hex2int conversion most likely works ok. You can try to open the result file in notepad to see if the conversion went as expected. And of course you should try to open the .gif file in a program that knows how to display images. Does it show up correctly?

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans