miercuri, 12 ianuarie 2011

How to open a .pdf or .txt file in C#

This is a simple question, with a very simple answer. I've been asking it myself and seeing other people ask it. A solution is to use the System.Diagnostics.Process.Start( ) method.
According to MSDN, using this method is very similar to typing the file's name in the Run dialog box of the Windows start menu.
For instance, if you have a .pdf file that you want to open, just use:
System.Diagnostics.Process.Start( "myfile.pdf" );
You can follow this link for more information: http://msdn.microsoft.com/en-us/library/53ezey2s.aspx.

For a text file, you can use the above method, or if you want to specifically open it with notepad you have to use:
System.Diagnostics.Process.Start( "notepad.exe", "myfile.txt" );

marți, 6 iulie 2010

Changing the location of My Documents in Windows CE

In this post I'll show you how to change the default location of the My Documents folder from the internal RAM to a flash disk location or SD card for your Windows CE device. This is mainly the case because Active Sync uses this folder to synchronize files with the device and initially, My Documents is located into a volatile memory region and all data saved there will be lost after a device reboot. Even worst is the fact that after the reboot, the synchronization process will erase all your files from the desktop PC as well.
So, in order to change the location of My Documents to the flash disk, open the Windows CE registry editor and open the key:
[HKEY_LOCAL_MACHINE\System\StorageManager\MSFLash]
and change the values of Folder and Name to "My Documents" ( without the quotes ).
Then choose to save your registry and reboot your device.
After the reboot, the Flash disk will appear renamed to "My Documents" and you can set-up a synchronized connection with the PC using Active Sync without having to loose the files every time you reboot.

marți, 13 aprilie 2010

Disposable generic list members

In this short post I will discuss about the necessity of calling Dispose on Disposable generic list members prior to remove them from the list.
Say you have a disposable type, e.g. MyDisposableType and create a generic list of such a type:

List myList = new List( );

Now, suppose that you use your list and at some point you need to remove one of the items using RemoveAt. With disposable types, the correct sequence should be:

myList[ itemIndex ].Dispose( );
myList.RemoveAt( itemIndex );

and this is because instances of non-disposed objects that are referred by MyDisposableType would still exist in memory after the object reference is removed from the list.
This is easy to verify using the .NET CF Remote Perfomance Monitor and taking GC Heap snapshots and monitoring the instance numbers of Disposable types referred by MyDisposableType.

joi, 4 februarie 2010

.NET CF Installed Version

In order for you to retrieve the current .NET Compact Framework installed on your Windows Mobile or Windows CE device, a simple thing to do is open the \Windows folder and execute cgacutil.exe. A dialog box will pop up stating the current version of Microsoft .NET Compact Framework ( e.g. [ 3.5.7283.0] ).
Cool!