How to create a new file

vishal.gargvishal.garg Member Posts: 2
edited 2004-12-01 in Dynamics AX
Hi

I want to create a new text file when I press some specific button and write some sales line details in that text file.Can anybody please let me know how to create a new text file by coding.

Thanks
Vishal

Comments

  • migimigi Member Posts: 10
    Try to use WinAPI class. There's a createfile-method.
  • g_dreyerg_dreyer Member Posts: 123
    Hi Vishal,

    You can either do it through dataports or through working with the files itself.
    I would suggest using a dataport by setting the filename and the filters (SETTABLEVIEW). It's much easier to maintain.
    Otherwise you can use the following code:


    Global Variables
    Name				Type    Size
    OutFile			File	
    OutFileName		Text	1000
    txtLine			Text	1000
    SalesLine		Record            Sales Line
    
    Code
         OutFileName := 'C:\SalesOrder' + SalesLine."Document No." + '.txt';
         OutFile.WRITEMODE(TRUE);
         OutFile.TEXTMODE(TRUE);
    	  
    	  SalesLine.SETRANGE(<set your filters>)
    	  if SalesLine.find('-') then repeat
    	  
    	      txtLine := <field1> + ',' + <field2> + etc.
    	      OutFile.WRITE(txtLine);
    		  
    	  Until SalesLine.NEXT = 0;
      	OutFile.close;
    


    You will probably need to add more code to so that you can avoid creating 'empty' files.

    Regards,
    Gustav
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    This is the Axapta forum, so I doubt if the answer given is correct ... unless the original poster asked his question in the wrong forum ;-)
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • g_dreyerg_dreyer Member Posts: 123
    Whoops!!! Who did that!!!

    My humblest apologies :oops: :oops:
  • HarishHarish Member Posts: 172
    Hi Vishal,

    For an example of how to create a file and to write data on that file using X++, please refer to -

    http://www.harishm.com/Navision/Code.html

    Regards,

    Harish Mohanbabu
    Harish Mohanbabu
    Long way to go before I sleep..
Sign In or Register to comment.