427437 (2) [Avatar] Offline
Even if in the "Now you try" section there are some very good hints (page 108 in MEAP v03), I experienced a couple of issues with the listing 11.5

open System.IO
let writeToFile date filename text =
let path = sprintf "%O-%s.txt" date filename
File.WriteAllText(path, text)

1) the automatic 'ToString()' invocation due to '%O' might generate a string that it's not compatible with a supported filename, so I had to force a good format by using something like 'ToString("yyMMdd")'. This also forced me to specify the type of the 'date' argument: (date:DateTime).

2) without specifying the current working directory somehow (i.e. in the Visual Studio project), the file is created in the temporary directory of the current user (i.e. C:\Users\xyz\AppData\Local\Temp) and this might be confusing of who might expect to find the file in the project's directory.

So I ended up with this version:

open System.IO
let writeToFile (date:DateTime) filename text =
let path = sprintf "c:\work\%s-%s.txt" (date.ToString("yyMMdd")) filename
File.WriteAllText(path, text)

Isaac Abraham (107) [Avatar] Offline
Good spot - fixed.