Loading ...

TrustedBlogs

Who is online?  0 guests and 0 members
home  »  blogs  »  Raghav Khunger

Communifire Blogs

Raghav Khunger : Most Recent postings

Raghav Khunger

C#: Casting with ENUM

11/22/2011 by Raghav Khunger · 0 · 289

In this blog I will show how to cast an int to enum, enum to int and string to enum. Let's make a sample enum: MyEnum.cs namespace Sample.Console { public enum MyEnum { Item1 = 1, Item2 = 2, Item3 = 3, Item4 = 4, Item5 = 5, } } 1. Int to Enum int integerValue = 2; MyEnum myenum = (MyEnum)integerValue; //Output: item2 2. Enum to Int MyEnum myenum = MyEnum.Item3; int integerValue = (int)my...

Raghav Khunger

C#: How to get the end of the day

11/22/2011 by Raghav Khunger · 0 · 228

Yeterday I had a requirement where I needed to find the end of day in datetime. I decided to make extension on datetime to achieve it. Below is the sample code: DateTimeExtension.cs: #region Using Directives using System; #endregion namespace Sample.Console { public static class DateTimeExtension { public static DateTime GetEndOfDay(this DateTime datetime) { return datetime.AddDays(1).Ad...

Raghav Khunger

Visual Studio: The breakpoint will not currently be hit. no symbols have been loaded for this document

11/21/2011 by Raghav Khunger · 0 · 241

This message irritates me when I encounter this while debugging my code. I am writing the solution below by which this can be avoided. Step 1: Go to Build >> Configuration Manager and select "Debug " as the option for Active solution configuration. Step 2 : Go to your web project properties >> Build >> General Uncheck the Optimized code checkbox. Step 3: Clean and Rebui...

Raghav Khunger

ASP.NET: Checkboxlist to string list

11/20/2011 by Raghav Khunger · 0 · 324

In this blog I will show how to get selected values of checkboxlist in ASP.NET. The selected value can be get by applying foreach iterator on checkboxlist items and then we can find the selected items. I decided to make an extension to do the same. Below is the code for it: Control Extensions: using System.Collections.ObjectModel; using System.Linq; using System.Web.UI.WebControls; names...

Raghav Khunger

Adding linebreaks in multiline textbox's text

11/20/2011 by Raghav Khunger · 0 · 935

Sometimes it is needed to add some text with linebreaks manually in textarea. It can be done by adding slash r and slash n (\r\n). Below is the sample code to do the same. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <form id="form1" runat="server"> <textarea id="myTextBox" style="width:500px;height:300px"&...

Raghav Khunger

GitHub Extensions Visual Studio: Commit not showing the new files added

9/25/2011 by Raghav Khunger · 0 · 1507

While working with GitHub extensions commit command in VisualStudio, I noticed it was not showing the new files which I added to my solution. This may be some bug of GitExtensions but I was able to resolve this by using the Git's "Git - Pending Changes" command. Instead of using git commit command I went for Git- Pending Changes option. To do the same right click the solution and click G...

Raghav Khunger

Good reasons/excuses NOT to use version/source control

9/23/2011 by Raghav Khunger · 0 · 367

Version control is a tool to manage the changes to documents, programs, and other information stored as computer files. It allow us to track what changes we did, revert the changes, do modifications and much more. Many people still have excuses for not using version control, I have listed some of them which I have encountered them saying: I'm the only developer in my company, I don't nee...

Raghav Khunger

GitHub Visual Studio: Apply Shortcut Keys

9/22/2011 by Raghav Khunger · 0 · 469

I find it handy using shortcut keys for various commands instead of command buttons while using VisualStudio. Today, while working with GIT in Visual Studio, I decided to apply shortcut keys to various commands (Commit, Pull etc.). Below are the steps which I used to do so: Step 1: Go to Tools >> Options Step 2: In Enviornment select keyboard option. Step 3: In Show commands contai...

Raghav Khunger

C# Regex: Extract the text between square brackets, without returning the brackets themselves.

9/19/2011 by Raghav Khunger · 0 · 554

In this blog I will show you how to extract the text between square brackets, without returning the brackets themselves. I will use REGEX class of in order to do so. Let's assume we have a string "Are you ready for regex [test text] magic?" and we want to extract "test text" from it ie. the text which lies in between the square brackets. Below is the sample code for it: using System.Text...

Raghav Khunger

How to detect IIS version in C#

9/19/2011 by Raghav Khunger · 0 · 415

In this blog I will show how to detect the IIS version using C#. We are going to make use of RegistryKey class which is the encapsulation for registry. Below is the sample code to detect the IIS version: using System; using Microsoft.Win32; namespace Sample { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Version version = GetI...

Raghav Khunger

ALTER TABLE DROP COLUMN xxx failed because one or more objects access this column.

8/12/2011 by Raghav Khunger · 0 · 875

I was dropping a column today from a table and I got the following error ALTER TABLE DROP COLUMN xxx failed because one or more objects access this column. The complete message which was coming in SQL Server Query Analyzer message pane was: Msg 5074, Level 16, State 1, Line 1 The object 'DF_TestTable_RankId' is dependent on column 'RankId'. Msg 4922, Level 16, State 9, Line 1 ALTER TABLE...

Raghav Khunger

SQL: Add a column with a default value in existing table

8/12/2011 by Raghav Khunger · 0 · 717

Few minutes back I was working with a table in my DB and I wanted to add a new column with a default value to my existing table. I decided to write a quick blog on the script I used for the same. Syntax: ALTER TABLE {TABLENAME} ADD {COLUMNNAME} {TYPE} {NULL|NOT NULL} CONSTRAINT {CONSTRAINT_NAME} DEFAULT {DEFAULT_VALUE} Example: Let's create an example to do the same. We will first create...

Raghav Khunger

IE Microsoft JScript runtime error: 'JSON' is undefined

8/11/2011 by Raghav Khunger · 0 · 1011

Recently while working with some JavaScript code, I encountered an error in IE7 "IE Microsoft JScript runtime error: 'JSON' is undefined" The error was coming at this line var data=JSON.stringify(......) ; I was getting this error only in IE7 and not in IE8 or IE9. Then I came to know that JSON.stringify was not the part of IE7. It is supported in IE versions greater than 7 i.e IE8, IE9 ...

Raghav Khunger

JavaScript: Prototype is not overriding the function/method

8/7/2011 by Raghav Khunger · 0 · 503

I recently encountered one question on forums "Prototype is not overriding the function/method in JavaScript" by a person. He was having the below code: function Test() { this.foo = function() { console.log('base foo'); }; } Test.prototype.foo = function() { console.log('overridden foo'); }; var test = new Test(); test.foo(); And running the above code the output was coming "base foo" as...

Raghav Khunger

C#: DateTime to Midnight datetime

8/4/2011 by Raghav Khunger · 0 · 570

Today I was working with a datetime field where I needed midnight datetime of that date. The solution was to subtract the time of day from the date. Here is the code for it: private static void Main(string[] args) { DateTime myDateTime = DateTime.Now; DateTime midnight = myDateTime.Subtract(myDateTime.TimeOfDay); Console.WriteLine("Original DateTime: " + myDateTime); Console.WriteLine("M...

Raghav Khunger

C#: DateFormat separator issue with ToString() method

8/2/2011 by Raghav Khunger · 0 · 1122

Today I was working with some dates and I encountered an issue while converting date to string. I noticed that inspite of providing the exact format to .ToString(<format>) method the separator was not coming correct after the date was converted to string format. I was using the below code: string date= DateTime.Now.ToString("M/dd/yy"); and the output I was getting is: As you might ...

Raghav Khunger

ASP.NET: Check a directory exists and create it if doesn't exists

8/2/2011 by Raghav Khunger · 0 · 692

Today I was working with a code where I needed to check whether a physical directory exists or not and if not, then I had to create it. I decided to write a quick blog on this. Below is sample code to do the same: string path = "D:\\test"; string basePath = Server.MapPath(path); if (!System.IO.Directory.Exists(basePath)) { System.IO.Directory.CreateDirectory(basePath); } Above with the h...

Raghav Khunger

C#: Convert a string having comma separated integers to an array of integers

7/31/2011 by Raghav Khunger · 0 · 1594

Today I saw a person on forums asking this "How to convert a string having comma separated integers to an array of integers" . He was having a string in this format "1,4,6,10,15,20" and he wanted to convert it into an array of integers. I decided to wrie a blog on this for converting the string to arrayof integers. Below is the code: using System.Linq; namespace MyConsole { internal clas...

Raghav Khunger

Using IsNullOrWhiteSpace in .NET 3.5

7/31/2011 by Raghav Khunger · 0 · 605

Today when I was working with one of my C# application I needed to use IsNullOrWhiteSpace method. You must be familiar with String.IsNullOrWhiteSpace which was introduced in .NET 4. But I was using .NET 3.5 for my application so I decided to write the IsNullOrWhiteSpace method as my own custom string extension method. I got the code for IsNullOrWhiteSpace by decompiling the code of Strin...

Raghav Khunger

What is the maximum size of Stack in IIS

7/16/2011 by Raghav Khunger · 0 · 643

Stack is a memory kept as a separate space for a particular thread execution. Today a person asked me what is the limit of stack for a particular thread in IIS. The answer is 256 KB . I collected the following information from By default, the maximum stack size of a thread that is created in a native IIS process is 256 KB By default, the maximum stack size of a thread that is created by ...

Raghav Khunger

JavaScript: How to deep copy an object

7/16/2011 by Raghav Khunger · 0 · 650

Today I was working with my client side code where I needed to do a deep copy of JavaScript object. I found an elegant way to do the same by using $.extend function of jQuery. This function can accept the first argument as boolean type variable which denotes whether we want a deep or shallow copy of an object. We can use it like below: var myDeepCopyObject = $.extend(true, {}, myObject);...

Raghav Khunger

ASP.NET: Use tild in HTML controls without runat server

7/6/2011 by Raghav Khunger · 1 · 601

A person asked me today that whether we can use tild(~) with HTML controls on ASP.NET pages without using runat server attribute. I replied him, yes, this is possible. We can write our controls like this: <a href='<%= Page.ResolveUrl("~/controls/mypage.aspx") %>'>XXX</a> Though I prefer using tild with runat server attribute but yes the above one can be other option too...

Raghav Khunger

jQuery: Select the first item of dropdownlist

7/6/2011 by Raghav Khunger · 0 · 783

Today a person asked aquestion on the forums on how to select the first item of dropdownlist with jQuery. I decided to write a quick blog on the code which I used to set it. <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"><...

Raghav Khunger

SQL Server: Rename a table

7/3/2011 by Raghav Khunger · 0 · 554

Yesterday a person asked me on the forums on how to rename a table in SQL Server. I told him the script sp_rename oldname,newname to do the same. I decided to write a short blog on the same to show with some scripts: Let's create a dummy table and insert some data in it: GO CREATE TABLE [MyTable] ([ID] INT IDENTITY,[Name] NVARCHAR(20)) GO INSERT INTO dbo.MyTable ( Name ) SELECT 'ABC' UNI...

Raghav Khunger

ASP.NET: Disable autocomplete for a textbox

7/3/2011 by Raghav Khunger · 0 · 1641

You might have enountered the autcomplete which appears by default on textboxes on forms. I was working with some textboxes(Password e.t.c) where I needed to disable the autocomplete. I did the same by setting the "autocomplete" property of textbox control from server side code. But then I decided to make a Custom server control for the same so that everytime I don't have to write the sa...

Product Spotlight

ASP.NET Hosting Spotlight

Join CodeAsp.Net for FREE Today!

It's fast, easy and free! Submit articles, get your own blog, ask questions & give answers in the forums, and become a better developer, faster.

enter your email address:

 

Quick Vote

What kind of email newsletter would you prefer to receive from CodeAsp.Net?