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 ...
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...
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...
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...
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 ...
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);...
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...
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"><...
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...
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...
Today I was in a need where I need to check in which set of ranges my input number falls. I was having a set of ranges with me like [101,200], [201,300],[301,400]... and I had to check in which of this set my input number falls. I decided to write a blog on the same. Below is the code for it: Code: using System; using System.Collections.ObjectModel; using System.Linq; namespace MyConsole...
Yesterday I was running a query against master.dbo.spt_values table and I encountered with this error: Msg 262, Level 14, State 4, Line 1 SHOWPLAN permission denied in database 'master'. I was not testing with "sa" user but with some new user "test" which I created. The fix for this was to GRANT the SHOWPLAN permissions to that user. Here is the fix for it: Fix Workaround: USE master GO ...
Today I was working with Captcha code in which had to generate random n digit alphanumeric string. I decided to go with Random Class and with the help of LINQ I was able to do this work in few lines. In this blog I will like to share the same code. Below is the code of my Utilities class which contains two overloaded methods for generating the random code. Utilities.cs using System; usin...
Today I was working with SourceGear Vault Client application and I encountered with the following error "Wait timeout for mutex after 30000 milliseconds". After searching few minutes on google I came to know that I need to install the latest version (4.14) in my case. You can get the latest downlods of SourceGear Vault from here http://sourcegear.com/vault/downloads2.html . After install...
I was working with my custom repeater control today. In it's header template I was having a ASP.NET Button control. I had to capture the click of this button control. There were other controls too for which also I needed to bind events. In this blog I will explain the example with button's click only. Below is the code: ASPX Code: <%@ Page Language="C#" AutoEventWireup="true" EnableEv...
I was working with NameValueCollection today where I had to remove the items of the collection in loop. But I was getting this exception "Collection was modified after the enumerator was instantiated" with the following code: foreach (var item in collection) { if (collection[item.ToString()] == "") { collection.Remove(item.ToString()); } } i.e by doing the iteration in the above manner I...
I was working with custom control today where I needed to catch the postback event of DropDownlist in DataBound Control. But I noticed that ASP.NET DropDownList doesn't have the CommandName and CommandArgument properties. Now if my DropDownList does the postback then how will my DataBound control's ItemCommand will get called? The solution was to make my own Custom DropDownList. In this ...
I was working with string.Compare method today where I had a requirement in which I needed to compare a string by ignoring the case but I found that the string.Compare method only accepts one arguement which is the string to be checked only. So I decided to make my own Compare extension method for string class. I am writing this blog to explain the same what I did in my case to compare t...
Today I was working with my application and I needed to add Querystring params to my current url at some place. While doing so I needed to keep one thing in my mind that if the current url already contains any querstring param I have to add "&" before my new param and if no param exists before, I have to add "?" . I decided to make a common code for it so that it can be used later on...
Today I was searching the information of how much memory my Graphics card has. I am writing this blog on the steps which I took to know the same. Below are the steps: Go to Start >> All Programs >> Accessories >> System tools >> System Information In the Left hand pane select Components>> Display On the right hand side you will see the memory of your Graphic...
Today I was in a need where I had to transfer my old laptop's data to the new one. I was not having the crossover cable with me so I decided to transfer the data using wireless network. I connected my two laptops using wireless and transferred my data. I decided to write a blog on the steps which I took to connect my two laptops. Below are the steps with screenshots of the Windows 7 OS. ...
Today I was a need where I need to remove all the rows of the table except first with jQuery. I decided to write a short blog on this. Below is the script to do it $('#foo tr:gt(0)').remove() where foo is the id of the table. The above code will remove all the rows greater than 0 index. Below is the complete code to test the same Code: <html> <head> <script src="http://aja...
I am used to work with dark colour themes for my applications like VS, notepad word etc. Thanks to dark colours which help me saving my eyes . There are plenty of resources from where you can find dark colour themes for Visual Studio but very few when the situation comes for SQL Server Management Studio. Recently I came across this resource , a very cool and simple way to import the colo...
In this blog I will discuss on variadic feature of functions in JavaScript. So what is variadic ? According to WikiPedia In computer programming, a variadic function is a function of indefinite arity, i.e., one which accepts a variable number of arguments. Support for variadic functions differs widely among programming languages. In JavaScript inside the function you can get the paramete...
While working with Visual Studio I found it very irritating when CSS errors pops up in the error list window and I really wanted this to turn off. You must have seen below kind of screen when CSS errors pops up Now in order to turn that off you need to go to Tools >> Options >> TextEditor >> CSS >> CSS Specific . There you will see Detect errors checkbox. You need...
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:
What kind of email newsletter would you prefer to receive from CodeAsp.Net?18