# Write txt file to controler

**URL:** <https://tech-community.robotics.abb.com/t/write-txt-file-to-controler/2452>\
**Category:** Developer Tools\
**Created:** [January 23, 2009, 7:44am UTC](https://tech-community.robotics.abb.com/t/write-txt-file-to-controler/2452 "2009-01-23T07:44:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![M\_Johnson](https://avatars.discourse-cdn.com/v4/letter/m/91b2a8/32.png) [@M\_Johnson](https://tech-community.robotics.abb.com/u/M_Johnson)\
**Post date:** [January 23, 2009, 7:44am UTC](https://tech-community.robotics.abb.com/t/write-txt-file-to-controler/2452/1 "2009-01-23T07:44:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RussD](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@RussD](https://tech-community.robotics.abb.com/u/RussD)\
**Post date:** [January 23, 2009, 2:56pm UTC](https://tech-community.robotics.abb.com/t/write-txt-file-to-controler/2452/2 "2009-01-23T14:56:25Z")

</div>

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.
