Tag Archive for '.net'

C#: How to get service name listening at specific port number?

How to get service name listening at specific port in C#? What you have as input is only two pieces of information: host name and the port number the service is listening at.

Solution

Apparently, .NET does not provide such feature so one needs to stretch a bit to get the answer. What I can suggest (I’m far from saying it’s good approach, though) is to get the name in two steps:

  1. Use netstat -a -o and parse the output (ouch!) to get ID of the process (PID) that is listening at given port number
  2. Perform a WMI call to get the name of the service: SELECT Name FROM Win32_Service where ProcessId = PID

Following this will give you what you want, but to be honest any time I need to parse output to get some information I feel anxious… This is the first place in the code where errors can be introduced.

If there is/are better/safer way(s) to retrieve service name having the host name and port it’s listening at, please share it.

Book review: LINQ Unleashed for C#

linq unleashed Book review: LINQ Unleashed for C#

I find this book relevant and very informative. If you want to master LINQ lingo, just read it.

For broader evaluation see my review on DZone.

P.S. DZone’s IT Book Zone is another great initiative. In short DZone gives you a free copy of a book and expects to receive its review in return. Fair agreement – one can stretch the envelope of IT domains for free, while DZone broadens thier public resources.

Comparison of .Net libraries for fetching emails via POP3

Sending emails in C# is easy; for basic use cases you don’t need external resources to send a note because .NET BCL already ships it. On .Net Developer Center, there’s a short description how to do it.

Now, how to fetch the email? It turns out it is not that easy – it’s not supported by .Net BCL. I spent a while researching for the best library that matched my purposes and I want to share my views on a couple of components I looked at.

Note: Please bear in mind I was interested only in a small piece of functionality such library could provide. My need was only to fetch an email (in plain text) with attachments. That was supposed to be done via POP3. I was not really interested in features like advanced sending emails (e.g. email templates), request and delivery receipts, support for iCalendar, email in HTML, etc. To sum up, I did not test libraries from that angle and therefore this comparison will not suit needs of all developers.

Continue reading ‘Comparison of .Net libraries for fetching emails via POP3′

Summary of Communities to Communities (C2C) 2009 Conference

C2C is a history now. I attended .NET stream and one session on SQL. The conference as a whole was very interesting, well organised, and basically developing. It was a Polish conference so most sessions were conducted in Polish but there were a couple of speakers from abroad too, and they spoke in English.

Basically I’m happy I had a chance to attend the conference. Below are my notes and comments. Please note they are my comments; should I write something which is not true or accurate, please let me know, sometimes pace was fast so I might have skipped something icon smile Summary of Communities to Communities (C2C) 2009 Conference
Continue reading ‘Summary of Communities to Communities (C2C) 2009 Conference’

Registering different versions of .NET Framwework

It’s possible to have more than one ASP.NET IIS installed and registrated on one machine (that runs Windows).
To check which version is currently registered run Command Line (Start/Run… and type ‘cmd’) and go to %SystemRoot%\Microsoft.NET\Framework\vXXX directory where %SystemRoot% is a special system-wide environment variable found on Microsoft Windows NT and its derivatives (read more on Wikipedia) and vXXX is the directory with ASP.NET IIS files.
Being in that directory, type aspnet_regiis -lv. You will be then given the list of installed/registered versions of ASP.NET IIS.

To register a new version of ASP.NET IIS, go to its direcotry in %SystemRoot%\Microsoft.NET\Framework (using Command Line) and run the following command: aspnet_regiis -i.

To unregister a new version of ASP.NET IIS, go to its direcotry in %SystemRoot%\Microsoft.NET\Framework (using Command Line) and run the following command: aspnet_regiis -u.

To learn more about ASP.NET IIS Registration Tool (Aspnet_regiis.exe) visit the description available on MSDN service.