Combining URL Paths

If you are like me, then you need to combine a base url path with another path to a web page or a service. Since base paths change often due to the application running from different environments, this is a common task. The .NET Framework provided use with a simple way of combining file paths, … Continue reading Combining URL Paths

Creating an MD5 String Hash

Below is code that will easily hash a string using the MD5 encryption. This is typically used when performing data integrity checks. using System.Security.Cryptography; using System.Text; namespace MyApp.Caching {    public static class CachingHelper    {       static public string CreateMD5Hash(string str)       {          var unicodeText = new byte[str.Length * 2];          Encoding.Unicode.GetEncoder().GetBytes(str.ToCharArray(), 0, … Continue reading Creating an MD5 String Hash

Converting Value Types

Converting a type like a string to an value type like integer, can easily cause an exception, which is a huge performance killer.  Hopefully you have wrapped the conversion in a Try Catch block, if not your program could take a nose dive and your users will be upset. Consider the code below that converts … Continue reading Converting Value Types

Type Design: Equals and HashCode

Good type design dictates that the Equals should always be overridden. This is actually a FXCop violation but 99.99% of types that I see, never has it (or GetHashCode).  Overriding Equals is pretty easy. Public Overloads Function Equals(ByVal obj As [Object] ) As Boolean Try Dim ci = DirectCast (obj, ComputerInfo ) Return (ci.OSFullName = … Continue reading Type Design: Equals and HashCode

Searching for Text Within a Stored Procedure

Here is a cool sp that will find any text within a stored procedure. Add this your Master database. CREATE PROCEDURE [dbo].[Find_text_in_sp] @text VARCHAR(250),@dbname VARCHAR(64) = NULL AS   BEGIN       SET nocount ON;       IF @dbname IS NULL         BEGIN             --enumerate all databases.               DECLARE #db CURSOR FOR               SELECT name               FROM   MASTER..sysdatabases             DECLARE @c_dbname VARCHAR(64)             OPEN #db             FETCH #db INTO @c_dbname             WHILE @@FETCH_STATUS <> -1 --and @MyCount < 500                 BEGIN                   EXECUTE Find_text_in_sp                     @text,                     @c_dbname                   FETCH #db INTO @c_dbname               END             CLOSE #db             DEALLOCATE #db         END --if @dbname is null         ELSE         BEGIN --@dbname is not null               DECLARE @sql VARCHAR(250)             --create the find like command               SELECT @sql = 'select ''' + @dbname +                           ''' as db, o.name,m.definition '             SELECT @sql = @sql + ' from ' + @dbname + '.sys.sql_modules m '             SELECT @sql = @sql + ' inner join ' + @dbname +                           '..sysobjects o on m.object_id=o.id'             SELECT @sql = @sql + ' where [definition] like ''%' + @text + '%'''             EXECUTE (@sql)         END --@dbname is not null   … Continue reading Searching for Text Within a Stored Procedure

See All of Your Code!

No matter how big your screen resolution is, it seems we write a line of code wider than the width of the code editor window in Visual Studio. One solution is to break up your line using carriage returns (now works without the “_” character in VB.NET too). This issue with this is that every … Continue reading See All of Your Code!

Saving & Loading Application Settings in C#

If your application uses application settings that are the scope of “User”, in C# you will need to add code that will save and load these settings during shutdown and startup (this is automatic when using VB.NET). In your Main() method of the Program.cs file add the first two lines below to load the settings … Continue reading Saving & Loading Application Settings in C#