Friday, November 23, 2018

X++ | d365FO - create temp file and save to local drive

Hi, this post shows a very simple sample how to create a temp file, and then save it to local drive.

 class Job_CreateTempFile  
 {      
   public static void main(Args _args)  
   {   
     str filePath,  
         filePathAndName,  
         fileContent = "01234567890123456789";  
     ;  
     // prepare file name  
     filePath = System.IO.Path::GetTempPath();  
     filePathAndName = filePath + 'f' + guid2str(newGuid()) + '.txt';  
     // Save file  
     File::SendStringAsFileToUser(fileContent, filePathAndName);  
     info(filePath);  
     info(filePathAndName);  
     info("done");  
   }  
 }  

The result looks like these below figures. The file path and name are generated, then save automatically on the folder. However you will see that it was saved on the download folder. So this code is not 100% completed, but would give some picture about this kind of task.










Until the next post!

No comments:

Post a Comment