Tag Archives: tutorial
Create and extract .zip files in C#
Sadly there aren’t many flexible or efficient ways to create .zip files in .NET prior to .NET 4.5. Thankfully some people took the initiative and created some very easy to use libraries for creating/extracting and updating .zip files. My two all time favourite are DotNetZip and SharpZipLib.
For this example I will be using the DotNetZip
library.
First you will need to download the library (.dll) either from http://dotnetzip.codeplex.com/ or from http://www.fluxbytes.com/?dl_name=DotNetZipLib_v1.9.1.8.rar. The file should contain quite a few libraries, so choose the one that suits your needs the most and add it as a reference in your project.
Posted in C#.
Tagged C#, csharp, DotNetZipLib, SharpZipLib, snippet, tutorial, winforms
Limit the number of months displayed by WordPress archives widget
Locate and edit your themes functions.php file. This can either be done in the admin panel by navigating to
Appearance -> Editor -> Click on functions.php file
or by directly editing the file which you can usually find under
wp-content/themes/<theme name>/functions.php
After opening the file simply add the following lines in it.
1 2 3 4 5 6 7 | function my_limit_archives( $args ) { $args['limit'] = 10; return $args; } add_filter( 'widget_archives_args', 'my_limit_archives' ); add_filter( 'widget_archives_dropdown_args', 'my_limit_archives' ); |
Replace the number 10 with the number of months that you want to display and you are done!
Posted in WordPress.
Tagged snippet, tutorial, WordPress, Wordpress archives
List Windows active processes in C#
Since some people were interested on how to get all the Window processes, I decided to make this tutorial. How you tailor it to your needs is up to you.
We start off by referencing System.Management
and adding the following on the top of our Form/Class:
1 2 | using System.Management; using System.Diagnostics; |
Then we need to declare our main classes. In this case that would be ManagementClass
and ManagementObjectCollection
in order to help us loop through the active process. Note that this can also be done by Process.GetProcesses()
but there is a limitation. Process.GetProcesses()
can only see the same bit process as your .exe files. So using that mean we wont be able to see all the processes, hence why we are using the two classes I mentioned above instead.
1 2 | ManagementClass management = new ManagementClass("Win32_Process"); ManagementObjectCollection mCollection = management.GetInstances(); |
After that we need to create our foreach loop which will help us get the information for each process we find and also a new listviewitem which we will be adding to our listview at the end of the loop so we can see the results.
1 2 3 4 | foreach (ManagementObject process in mCollection) { ListViewItem newListViewItem = new ListViewItem(); } |
For the sake of this tutorial we will only be concentrating in the process id/name/location and finally the description.
Posted in C#.
Tagged C#, csharp, ManagementClass, ManagementObjectCollection, processes, snippet, tutorial, Win32_Process, winforms