Category Archives: Development

C# reading from and write to text file

CSharp sample for reading from a text file and writing to a text file.

//Reading from a text file      

System.IO.StreamReader srFile = new System.IO.StreamReader(@"c:foo.txt");

string str = srFile.ReadToEnd();



//Writing to a text file

string lines = "foobar";

System.IO.StreamWriter swFile = new System.IO.StreamWriter(@"c:bar.txt");



Uncompress MSI File

Sometimes I need to unzip MSI file to view its content without actual installing it. I used to use a 3rd party tool named 7zip to extract MSI. Today I discover there is much easier way to do this with windows build in tool msiexec.exe

The use msiexec to uncompress MSI file, you need to open a command line and run type following:

msiexec /a <YourPackageFullPath> TARGETDIR=<ExtractedMSIFullPath>

Replace <YourPackageFullPath> with full path of MSI file, <ExtractedMSIFullPath> with the target folder you want MSI files to be extracted to.

For example, to extract c:setup.msi, run following command:

msiexec /a c:setup.msi TARGETDIR=c:ExtractedMSI

The uncompressed setup.msi and all files along with fold structures will be extracted into  c:ExtractedMSI

Note: For Vista/Win7 with UAC turn on, the above command needs to be run from elevated command prompt.