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, ...
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");
}

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator 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?

  • Martin Dráb Profile Picture
    236,513 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?

  • EDV Abteilung Profile Picture
    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
    236,513 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.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,850

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 519 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans