Wednesday, September 28, 2005

Embedding and using text resource files in C# (also a little about normally embedded resources)

Sometimes, you might want to embed an entire text file (or any other format for that matter) into your .Net assembly. (As opposed to creating a resource file that might contain culture specific resources for access at runtime) To do this you add the file to your project. You then have to set the file to be an embedded resource. (this is done on the property page of the file). Once that is done you can use the GetManifestResourceStream method of the System.Assembly class to retrieve the data. You can do this using the following code snippet: Assembly currentAssembly = Assembly.GetExecutingAssembly(); using( Stream stream = currentAssembly.GetManifestResourceStream("projectName.Folder.resourceName.extension") ) { try { using( StreamReader reader = new StreamReader(stream) ) { string text = reader.ReadToEnd(); using (StreamWriter sw = new StreamWriter(filePath,false,System.Text.Encoding.ASCII)) { sw.WriteLine(text); } } } catch(Exception e) { MessageBox.Show(e.Message); } One of the important things to remember is that when retrieving the resource you need to fully qualify its name. Normally this will be ProjectName.Folder.ResourceName.Extension. This name is case sensitive (omit the folder if the resource file is in the root folder of the project). If instead, you want to create the resource file to contain multiple items within it (normally used to store grouped items, like strings for a specific culture), then you would use the ResourceManager. To do this you create a resource file: IResourceWriter rw = new ResourceWriter(ResourceFileName); and then call AddResource to attach each item. rw.AddResource(resourceItemName,resourceItem); To read the resource file you can open it directly or embed it in the assembly and open it from there. To read the resource file directly: IResourceReader rr = new ResourceReader(resourceFileName); and then use the enumerator to read the key value pairs of resource items. To read the resource from the assembly. First embed the resource into the assembly, by adding the file to the project and setting its property to Embedded resource. then use the following snippet: ResourceManager rm = new ResourceManager(resourceFileName,Assembly.GetExecutingAssembly()); string text = rm.GetString(resourceItemName); object val = rm.GetObject(resourceItemName);

Windows XP Hacks

A List of Windows XP Hacks This page has some of the hacks from the book of the same name.

Sunday, September 25, 2005

Monday, September 19, 2005

PDC 05 Slides

The Slides from last weeks Professional Developers Conference in the US are now available for download from:

http://commnet.microsoftpdc.com/content/downloads.aspx

So if you weren't lucky enough to go - you can download all the presentations :)

Microsoft Setup Blogs

These are some microsoft blogs dealing with Setup.

http://blogs.msdn.com/pmarcu/

http://blogs.msdn.com/hgao (Hong - Program Manager)

http://blogs.msdn.com/pgiffin (Pete - Test Lead)

Tuesday, September 13, 2005

How can I quickly find all the listening or open ports on my computer?

These tools will show you the ports that are open or closed on your computer.

Net Monitor v0.90

Shows listening and connected ports and logs them to a file if you want.

Download the free 0.90 version from HERE (251kb)

Sysinternals TCPView v2.33

This tool will also show the process name that has the port opened and will let you terminate it. The program will also show newly-connected ports in green, while closed ports will be colored in red.

Download from HERE or from THERE (35kb)

LPS - Local Port Scanner 1.2.2

Freeware, will scan for any given local port, has some built-in Trojan detection functionality. Also lets you scan a remote system and will log the output.

Download from HERE or from THERE (562kb)

Smartline Active Ports v1.4

Freeware, easy to use tool for Windows NT/2000/XP that enables you to monitor all open TCP and UDP ports on the local computer. Active Ports maps ports to the owning application so you can watch which process has opened which port. It also displays a local and remote IP address for each connection and allows you to terminate the owning process. Active Ports can help you to detect Trojans and other malicious programs.

Note: This tool seems not to work under Windows Server 2003.

Download from HERE or from THERE (450kb)

MSDN Magazine Contents: October 2005

MSDN Magazine October 2005 is online Get the CHM version from http://msdn.microsoft.com/msdnmag/issues/05/10/MSDNMag0510.chm

C at Work: Writing, Loading, and Accessing Plug-Ins -- MSDN Magazine, October 2005

This article talks about how to create a plugin framework using .NET. It also goes into details of how a Native application can be made to load up plugins written in .NET languages. (http://msdn.microsoft.com/msdnmag/issues/05/10/CatWork/default.aspx) Also of interest is an articel referenced here that talks about optimizations that can be made for such scenarios. Joel Pobar from the CLR team wrote a terrific article for the July 2005 issue of MSDN Magazine (Reflection: Dodge Common Performance Pitfalls to Craft Speedy Applications)

CCleaner - Crap Cleaner free software download

Crap Cleaner is a useful tool to clean up the crap that gets accumulated on your computer. It cleans the browser cache, log files and does an excellent job of cleaning the registry too. Other tools that I regularly use. Spyware cleaning: AdWare AntiVirus: AVG AntiVirus free edition (its free and pretty good) Microsoft AntiSpyWare.

Google Map API

This google API map hack shows population information. Its a cool use of the map API from GOOGLE Analygis

Thursday, September 01, 2005