Wednesday 8 June 2011

IE Developer Toolbar disabled

I am using Windows XP and IE7. Recently, after some updates ran on my system I found that the IE Developer toolbar is not working. When I looked further, I found that “Enable third-party browser extensions*” is disabled in Tools->Internet Options->Advanced->Browsing. It’s grayed out, and there is no way it can be checked (tried through system administrator also). So what was the solution?
Somewhere after a lot of googling/binging, I got this solution:
Go to command prompt, type regedit, enter. The registry key window will open.
Go to HKEY_LOCAL_MACHINE->SOFTWARE->Policies->Microsoft->Internet Explorer->Main
Here you will see the Data as “no” for “Enable Browser Extensions”. Set it to “yes”. Hurray!!!
IE Developer Toolbar is working. If you check in Internet Options, the browser extension checkbox is checked.

Thursday 19 May 2011

Column values as a single string - MS Sql Server

There are situations where you need the resultant values of a single column to be displayed/processed as a single string. So here goes the query:

DECLARE @Str VARCHAR(MAX)
SELECT @Str = COALESCE(@Str+',' ,'') + CONVERT(varchar,Column1) FROM MyTable
SELECT @Str

Multiple Count from Single Table Sql Server

Recently my collegue was working with a query where he needed multiple counts from a table with different conditions. Say its something like a company has multiple office buildings with multiple floors. They need the count of total space for each floor of each building and empty space with the same conditions.
The query I referred was like this:

SELECT SUM(CASE WHEN condition1 THEN 1 ELSE 0 END) count1, SUM(CASE WHEN condition2 THEN 1 ELSE 0 END) count2 FROM yourtable

Customizing it to my need I wrote the following query

SELECT SUM(CASE SeatStatus WHEN 0 THEN 1 ELSE 0 END) FreeSpace, COUNT(Seat) TotalSpace FROM MyTable

Friday 25 March 2011

Find Last Modified File in a folder

Let me first explain the requriements & constraints and then arrive at the solution.
I have a folder in a designated path (here C:/Testing), in which there are a lot of files. My requirement need me to find a specific type of files (here *.txt) in the folder. Of all the files of that type, I have to choose only those files who have a specific name (here Hello) and get the one which was the latest modified.

Here we can see the folder with 6 text files.











5 of the files name contains "Hello", so they fulfill our criteria. Although the 6th file "little.txt" was latest modified of all the files, our logic should not choose it; instead it should choose "Hello4.txt" since it was the latest modified of the other 5 files, that matches our criteria.



string dirname = @"C:\Testing";
string[] txtFiles = System.IO.Directory.GetFiles(dirname,"*.txt");
DateTime lastmodified= Convert.ToDateTime("01/01/1900");
string LastModifiedfile = string.Empty;
foreach (string filenm in txtFiles)
{
if (filenm.Contains("Hello"))
{
if (File.GetLastWriteTime(filenm) > lastmodified)
{
lastmodified =
LastModifiedfile = filenm;
}
}
}
Response.Write(LastModifiedfile + File.GetLastWriteTime(filenm);" at "+lastmodified+" was last modified.");



Hence we successfully get the result as:

Dropdownlist - Adding tooltip for each listitem

There are times when you are designing a page with space constraint for the cotrols.
One such case can be with the Dropdownlist whose items may need more space then what it was allocated for. In this situation the user will not be able to see the complete text of the listitems. A solution to this situation is to add tooltip for the listitems.

Consider here, we have the Dropdownlist: 

<div style="width: 600px; margin: auto;">
<div style="width: 150px; float:left">Account Name: </div>
<div style="width: 400px; float:left">
<asp:DropDownList ID="DropDownList1" runat="server" Width="120px">
<asp:ListItem Value="1">Application Services</asp:ListItem>
<asp:ListItem Value="2">Toyota Motors Private Limited</asp:ListItem>
<asp:ListItem Value="3">Ford Motors Private Limited</asp:ListItem>
</asp:DropDownList>
</div>
</div>



Which leads us to have a dropdownlist as below.






We added the tooltip for each listitem.

foreach(ListItem _listItem in this.DropDownList1.Items)
{
_listItem.Attributes.Add("title", _listItem.Text);
}



Hence we have the Dropdownlist with tooltip as shown below: