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 :
Microsoft Dynamics AX (Archived)

AX attachment file size

(0) ShareShare
ReportReport
Posted on by 1,435

Hello everyone,

I have the following challange:

I would like to check the filesize of attachments, and calculate the total size of attachments of a certain 'type'. For example I have a filetype "PDF drawing". If an article has 3 attachments of this type, one of 1MB, one of 2MB and one of 3MB, I would like code that calculates the 6 MB for me.

Unfortunately I cannot find the filesize option in a Docuref method. Can anyone point me in the right direction?

Thanks in advance.

Willem.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Pradeep Itnal Profile Picture
    3,248 on at

    WinAPI::FileSize will help you to find file size. Let me know if it helps.

  • Wvduren Profile Picture
    1,435 on at

    Thank you! That works.

    For the rest of the world here I made an example of code:

    [quote]

    static void Filesizetest_WD(Args _args)

    {

    int bytes;    
    real kb;
    real mb;
    real gb;

    bytes=WinAPI::filesize(@"C:\DOC-008276.rar");
    kb=bytes/1024;
    mb=kb/1024;
    gb=mb/1024;

    info("This file has the following size:");
    info(strfmt("Bytes: %1", bytes));
    info(strfmt("KiloBytes: %1", kb));
    info(strfmt("Mega Bytes: %1", mb));
    info(strfmt("Giga Bytes: %1", gb));

    }

    [/quote]

    The only thing I see is that above a certain size, the int becomes negative, but this does not hinder me for my requirements.

  • Wvduren Profile Picture
    1,435 on at

    Ok, so I tested a little more. My code works, but somewhere in the while-loop it just stops. The "Ready" message on the end of my code never displays. Although I get the right output, it stops on 3/4 of all inventtable records.

    Here my code, anyone an idea what I am missing?

    [quote]

    static void Test_Willem(Args _args)
    {

    InventTable inventtabel;
    DocuRef docuref;

    int bytes;    
    real kb;
    real mb;
    real gb;
    real totaalmbproduct;

    Counter teller;
    Counter teller2;

    String255 itemid;
    String255 bestandsnaam;

    boolean fileexists;

    while select inventtabel
    {

       fileexists=false;
       itemid=inventtabel.ItemId;
       totaalmbproduct=0;
       teller=0;
       teller2++;

           while select docuref where docuref.RefTableId==inventtabel.TableId && docuref.RefCompanyId==inventtabel.dataAreaID &&    
           docuref.refrecid==inventtabel.recid && docuref.TypeId=="Te_Verst"

           {            

            bestandsnaam=docuref.CompleteFilename();
            teller++;
            fileexists=WinAPI::fileExists(bestandsnaam);

             if(fileexists==true)
              {
              bytes=WinAPI::filesize(@bestandsnaam);
              kb=bytes/1024;
              mb=kb/1024;
              gb=mb/1024;

              totaalmbproduct=totaalmbproduct+mb;

              }  

            }

              if(totaalmbproduct>10)
              {
              info(strFmt("Articlenumber: %1 , Attachments: %2, Total MB for this part: %3 mb",itemid,teller,totaalmbproduct));
              }

       }

      info(strfmt("Ready! %1 products analysed",teller2));

    }

    [/quote]

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans