RobotStudio event

Write txt file to controler

Hi.
 

I'm trying to create,  write to and read from a txt file on the controller.

I become no error from my code but nothing is written on the controller (hd0a/Temp).

The code works in virtual controler but not in a real controler.

I have attached my code below from my real controler.

Does someone know what I'm doing wrong?

 


string
sDir = ctrl.FileSystem.LocalDirectory;

String sFileName = sDir + "/RabApplication2.txt";

DateTime dDate = DateTime.Now;

 


// Check if the file exists

if (!System.IO.File.Exists(sFileName))

{

// Sparar datum i filen fA?r att kontrollera antal dagar frA?n

System.IO.StreamWriter sw = new System.IO.StreamWriter(sFileName);

sw.WriteLine(crypto.EncryptString(dDate.ToString(), sCryptoKey));

sw.WriteLine(crypto.EncryptString("Not licensed", sCryptoKey));

sw.Close();

}

 
I'm using RW5.10 and RAB 5.10
 

Best regards M Johnson
M Johnson2009-01-23 07:51:09

Comments

  • You are going about it the right way, but the .Net functionality doesn't know anything about the robot file system. Local directory by default is actually the directory "/temp" on the FlexPendants's RAMdisk.
     

    So, what you are doing is creating the file on the flexpendant. That is what you have to do, but when you are finished you need to call FileSystem.PutFile to copy the file from the local directory (FP) to the remote directory (by default, the HOME directory of the active system).

     

    Also, you may find that "Now" doesn't give you an accurate time, you might want to use the controller's date and time.
    RussD2009-01-23 15:11:33
    Russell Drown