Google Shortener is a service provided by Google to create short URLs. Google Shortener has been available for some time now but only recently Google released a public API to access this service programmatically. Today I decided to try it out and wrote some C# code to work with the API. I will describe [...]
This post shows you how to output data to a Console in a Windows Forms Application. I use this technique religiously when developing Windows Forms applications. Debugging is much simpler when you can see information on what your application is doing in a Console. Of course the onus is on you as developer to output [...]
To get width and height of an image we can use System.Drawing.Image class. This code snippet shows how to retrieve width and height of an image.
string filePath = @"c:\deepak\MeeGo.jpg"; Image img = Image.FromFile(filePath); Console.WriteLine(string.Format("Height: {0}",img.Size.Height)); Console.WriteLine(string.Format("Width: {0}",img.Size.Width));
To convert a Hexadecimal to a number we can use an overload of Convert.ToInt32 method.
Using the overload I can convert for example hex string “BB” to a number.
int number = Convert.ToInt32("BB", 16);
And the number variable gets assigned value of 187.
This is where reflection comes in handy. The following code snippet shows you how to get the name of executing assembly.
string assemblyName; assemblyName = System.Reflection.Assembly.GetExecutingAssembly().FullName; Console.WriteLine(assemblyName);
Output for the above code returns the fully qualified name as shown below
To just get the Assembly name we can use [...]
This snippet shows you how to get information about all CD / DVD drives on your machine using WMI and C#. To run the code you need to add reference to System.Management.
ManagementObjectSearcher mgmtObjects = new ManagementObjectSearcher("Select * from Win32_CDROMDrive"); foreach (var item in mgmtObjects.Get()) { Console.WriteLine("Drive Letter – \t" + item["Drive"]); Console.WriteLine("Name – \t" [...]
To do this you will need to add references to System.Drawing and System.Windows.Forms. Make sure that you have following using statements:
using System; using System.Drawing; using System.Drawing.Imaging; using System.Windows.Forms;
In your method add this code. It will take a screenshot of your primary screen and save it to a file.
Bitmap bitmap [...]
This code will retrieve a list of currently running process on a machine and write their names to console.
// Get A List of process using // System.Diagnostics.Process class List<Process> processes = Process.GetProcesses().ToList(); // Write them out to Console processes.ForEach(x => Console.WriteLine(x.ProcessName));
I have a confession to make. When I saw var keyword for the first time I did not like it at all. My first opinion was that var was so variant like. Call me a control freak but I like to clearly see what I am declaring. And var was something I thought made the [...]
While browsing forums today I came across a question which asked for a solution to download a file from a web server programmatically. The solution is very simple and below is the code which achieves the goal. Here I am downloading a file asynchronously on Button Click.
1: private void buttonDownloadFile_Click(object sender, EventArgs e) 2: [...]
To make an object cloneable in .NET we should implement ICloneable interface. ICloneable is a simple interface with only one method Clone(). In this post I will show you how to make a deep clone of an object.
class Program { static void Main(string[] args) { Customer c1 = new Customer { FirstName = “John”, [...]
To get a list of installed applications we need to look into registry. Microsoft.Win32 namespace contains objects which can be used to work with Windows Registry. In this post I will show you some code where I use the power of LINQ to retrieve and display a list of all applications installed on a machine.
[...]
Top Posts
- LINQ To SQL Tutorial
- LINQ To SQL Join On Multiple Conditions
- Code Sample: Programmatically Download File Using C#
- Windows 7 Control Panel In Classic Mode
- More Details Emerge On Microsoft Master Certification
- Use SqlConnection With LINQ To SQL
- Free Icons And Images With Visual Studio 2008
- Capture XML In WCF Service
- Dynamic Sort With LINQ
- StyleCop Tutorial
Tags
.Net 2010 ADO.NET ASP.NET Azure Blogging Books Browsers C# Certification Cloud Computing Code Snippets Community Data Services Eclipse Entity Framework Google IDE Java LINQ Mac Microsoft Museum NetBeans Office Oracle REST SharePoint Silverlight SQL Server T-SQL Tips Tools Training Visual Studio Visual Studio 2010 WCF Web Windows Windows 7 Windows Forms Windows Live WMI WPF XAML

