problems with record variable subtype "File&qu

NagiNagi Member Posts: 151
Hi,

I'm trying to use a record variable with subtype File to loop through files in a folder and attach these to an e-mail. However, for some reason, the record variable keeps remembering previous files it looped. The result is that it skips files currently in the folder and, when trying to delete files after they've been attached to the e-mail, breaks on error when files doesn't exist.

It's as if the record variable constantly uses "xRec" as a record set. I've tried using CLEAR and CLEARALL, both CLEAR and RESET, etc. without result so far. If you close the application and then reopen it, the record variable will fetch the correct set of files.

The code below is from codeunit Mail.
SalesSetup.GET;
SalesSetup.TESTFIELD("Path E-Mail Attachments");
recFile.RESET;
recFile.SETRANGE(Path,SalesSetup."Path E-Mail Attachments");
recFile.SETRANGE("Is a file",TRUE);
IF recFile.FINDSET THEN
  REPEAT
    BSTRConverterAttachFileName.ResetBSTR;
    BSTRConverterAttachFileName.AppendNextStringPortion(recFile.Path + recFile.Name);
    OAttachments := OSendMail.Attachments;
    OAttachment := OAttachments.Add(BSTRConverterAttachFileName);
    ERASE(recFile.Path + recFile.Name);
  UNTIL recFile.NEXT = 0;

If any one can help me with this, then I'd be very grateful.

Cheers!

Answers

  • tinoruijstinoruijs Member Posts: 1,226
    Just recently had the same problem.
    You should add the following piece of code:
    recFile.SETRANGE(Path,'c:\'); 
    IF recFile.FINDFIRST THEN;
    

    Just use it instead of the recFile.RESET;.
    Like you said. It doesn't do anything..

    Tino Ruijs
    Microsoft Dynamics NAV specialist
  • kinekine Member Posts: 12,562
    Yes, this is known problem of the File table. Many people are solving that. I think that first post about that was 4 years ago...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • NagiNagi Member Posts: 151
    Big thanks to tinoruijs! The solution worked perfectly.
Sign In or Register to comment.