Browse by Tags
All Tags »
C# »
DEV (
RSS)
Using Reverse Geocoding to Find an Address I had a request from a colleague of mine to help him with a geocoding problem. The colleague needed to find an address by a given latitude and longitude which were supplied by a smartphone consumer. The example in this post will show you how you can use Google geocoding API in order to achieve that using C#. Reverse Geocoding (Address Lookup) Geocoding refers to translating an address into its location or coordinates. The reverse of it is address lookup...
Configuring WCF Data Services using Lambda Expressions One of the things that I avoid when I’m writing code is the use “magic strings”. Hardcoded strings are a code smell and should be rarely used. When using WCF Data Service configuration object you’ll have to pass the entity set’s string name to the configuration methods which as I wrote I would like to avoid. This is why in today’s post I’m going to extend the DataServiceConfiguration object to support lambda expressions instead of string parameters...
Back to Basics – Reading a File into Memory Stream Today I was asked to help a developer with a simple task she had. That task included reading an image file into a memory stream in order to send the image through an e-mail attachment. This post will show you how to do exactly that. Reading a File into Memory Stream Here is the code for reading the file into a memory stream: using (FileStream fileStream = File.OpenRead(filePath)) { MemoryStream memStream = new MemoryStream(); memStream.SetLength...
Back to Basics – Null-Coalescing Operator Yesterday during an EF4 course that I’m giving at a customer I showed an example for a property that is set using the null-coalescing operator . Since some of the students asked me what is this operator, I gave a small explanation and thought that it’s something that I can share here in the blog. So here it goes… Null-Coalescing Operator The null-coalescing operator or ?? can be very useful when you want to check nullity of a reference type or nullable types...
Adding a Javascript Block Into a Form Hosted by WebBrowser Control Today I found myself with a need to add a javascript block into a WebBrowser control in order to do some work. This post will show you the steps to do exactly that. The Problem In a project I’m consulting for there was a need to dynamically add a javascript block into a web form that is hosted inside a WebBrowser control. So what can we do? The Solution We can use the Microsoft HTML Object Library to achieve the task. The Microsoft...
Book Review – C# in Depth – What You Need to Master C# 2 and 3 In the last weeks I read the book “ C# in Depth – What You Need to Master C# 2 and 3 ” that was written by Jon Skeet . You might ask yourself why I bothered reading a book about C# 2 and 3. The answer is very simple. Knowing some material isn’t enough and reading leads to wide and deeper knowledge. One of the first things that I recommend people who ask me how can I learn and gain programming knowledge is reading good technical books...
Performing Queries Against Active Directory Domain Services One of the missions that needed my attention lately was to check whether a user exists in an enterprise Active Directory . The post will show exactly how to perform such a query. The DirectoryEntry Class The DirectoryEntry class represent an entry in Active Directory . That entry live in memory when created and changes that you perform on it won’t be submitted to Active Directory unless you call the CommitChnages method. That class can be...
Quick Tip – Making Beep From the PC Speaker Using P/Invoke I was asked yesterday how can we perform a beep sound from the PC speaker. This is something that is needed in one of the applications that I’m consulting for to indicate a successful transaction (don’t ask me way…). Setting the Environment We first need to add the using for Runtime.InteropServices : using System.Runtime.InteropServices; Then load the unmanaged dll of kernel32.dll with the method signature for Beep which...
Error CS0029: Cannot implicitly convert type Using WSDL Tool Today I was asked by one of developers I work with to check an error he got after he generated a proxy class with the wsdl.exe tool from a third party wsdl he got. The error was generated in runtime when he tried to use the generated class and it was something like: Unable to generate a temporary class (result=1). error CS0029: Cannot implicitly convert type 'A' to 'A[]' After searching in the internet I found that there...
Reading a Xml File in T4 Templates After I wrote the post about the use of T4 templates in EF4 , I played with them for a while (not in EF but generally with T4 templates ). In an old project that I’ve created almost 3 years ago which automated the use of lookup tables I had an enum. That enum was meant to be the connection between an Xml node names and was heavily used in the application. For each Xml node I needed to add an entry in the enum. So I thought what the hell lets see if I could have...
Applying Strategy Pattern Instead of Using Switch Statements Once in a while I’m stumbling on switch statements during a Code Review session. Whenever this is happening my first reaction is to understand why did the developer use it. Since using switch statement sometime implies spaghetti code and also can get very crowded (in case statements of course) in this post I’m going to show an alternative method that I prefer to use. Alternative Method for Switch Statements Whenever you start to use a switch...
Building a Custom Site Map Provider In the last ASP.NET course I delivered I was asked how to build a custom site map provider . This post holds the answer. You can download the full example from here . Building a Custom Site Map Provider There are times that our requirements demand that our site navigation will not be based on the default site map provider . Such times are for example when we want to use a database table to hold our site navigation . In these times we can create a custom site map...
Back to Basics – Exposing UserControl Events This morning I saw Shlomo ’s post ( in Hebrew ) that explain how to expose events in a UserControl in order to enable the page to register to that event . This post will show a different solution to do the same thing and also explain my opinion in regard of whether to expose events through UserControl or not. Should We Expose UserControl Events? One of the things that I always explain when I’m being asked my opinion about exposing UserControls...
Quick Tip – Using the ShouldSerializeXXX methods Something that I encountered last week. The ShouldSerialize methods are optional methods that you can provide for a class property. These methods are built as ShouldSerialize PropertyName and inside of them you can provide a check that will determine whether the property should be serialized or not. Of course this can be achieved only in serializable classes. An example of use: public string Text { get; set; } public bool ShouldSerializeText...
Back to Basics – Calculating MD5 Hashing Yesterday I needed to use a hashing algorithm for a given task. I chose to use the MD5 hashing algorithm and in this post I’ll show how to calculate MD5 hash from a given string. What is MD5 Hashing Algorithm? MD5 is a very widely used hashing function that commonly used to check the integrity of files or strings. When using MD5 There is a small possibility of getting two identical hashes to two different strings. It is very useful for storing passwords...
More Posts
Next page »