Code conversion (C#/VB) in Silverlight |
Written by Ian Elliot | |||||||
Tuesday, 24 August 2010 | |||||||
Page 3 of 3
The file handlersAll that remains now is to define the code that loads a file to textBox1 and allows the user to save the contents of textBox2 to a file. There is nothing strange new or odd about this code - but it is relatively recent that Silverlight allowed users to save and load files. You might think that it would be a security risk but as the user picks the file to load and the location to save to it probably isn't too bad. The load file button is easy enough. First we setup the parameters for the OpenFileDialog: private void button2_Click( You can set the Filter to a range of options .cs, .vb and so on but in this case All Files seems like a reasonable default. The user can also only select one file at a time - you could change this so that multiple files were loaded but it doesn't seem to be a useful option. Next we show the dialog box and process the result: bool? userClickedOK = Notice the use of the ReadToEnd method to avoid having to write an input loop with a test for EOF - such convienences are well worth having! The save file routine is just as simple: private void button3_Click( Again notice the use of Write to simply write everything in the TextBox out to the file without having to write a loop. Trying it outYou can see the convertor in action in the following screen dump - converting its own code into VB .NET
Of course as this is a Silverlight application you can try it out for yourself at our Resources and Tool section . You need to keep in mind the initial comments about only trying to convert complete classes and only converting correct code. To access the code for this project, once you have registered, click on CodeBin.
If you would like to be informed about new articles on I Programmer you can either follow us on Twitter, on Facebook or you can subscribe to our weekly newsletter.
<ASIN:1430229799 > <ASIN:1430224258 > <ASIN:0470650923 > <ASIN:1847199844 > <ASIN:143022455X > |
|||||||
Last Updated ( Tuesday, 24 August 2010 ) |