Important point to consider when using a List

clock August 23, 2010 23:24 by author Nazar Rizvi

People who deal with performance issues and high-end systems already know about the effective ways to use List<t> from System.Collections class. The msdn documentation for List<t> is available here: List<t> msdn Documentation 

Usually this will never be an issue unless you are dealing with high-performance applications or mobile applications. Whenever a new List<T> is created, the constructed capacity is 0. This utilizes minimal memory. But as you keep on adding items to the list the capacity grows exponentially i.e. 4, 8, 16, 32, 64 …

Run this piece of code to verify yourself.

Code Snippet
  1. List<string> list = new List<string>();
  2.             Console.Write(list.Capacity);
  3.             // This would output '0'
  4.  
  5.             list.Add("something");
  6.             Console.Write(list.Capacity);
  7.             // This would output '4'
  8.  
  9.             for (int i = 0; i < 4; i++)
  10.             {
  11.                 list.Add(i.ToString());
  12.             }
  13.             // List contains 5 items
  14.  
  15.             Console.Write(list.Capacity);
  16.             // This would output '8'

 

Now this can be gracefully handled by providing the capacity in the constructor as shown below:

Code Snippet
  1. List<string> newList = new List<string>();
  2.             newList.Capacity = 5;
  3.             newList.Add("junk");
  4.             Console.Write(newList.Capacity);
  5.             // This would output '5'

Currently rated 3.0 by 3 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


.NET Helper to create CoolIris media RSS Feed /File Uploader - Code Sample

clock August 8, 2010 19:00 by author Nazar Rizvi

I have been using CoolIris for websites in order to maintain my photo gallery. Initially editing the XML manually using TextPad was cool but after few occasions it ended up being a pain to manage.  Below is a basic web form I created to upload and edit RSS feed to work with the CoolIris control I use. You can use the attached piece of code to work with your web server (Modify it as needed)

 SourceCode: 

Currently rated 3.9 by 7 people

  • Currently 3.857143/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Firepass or any other VPN with Safari 4.0 on Snow Leopard

clock January 7, 2010 08:53 by author Nazar Rizvi

Many of you might have had difficulty running Firepass or any other VPN software on Snow Leopard. One can use Firefox to achieve this bu this leads to Kernel Panic Attack while closing down the browser. The solution to this is:

Go to your applications folder --> Right Click on 'Safari' Application --> Select 'Get Info' --> Check the checkbox 'Open in 32-bit mode'.

This should take care of it for you. 

Currently rated 3.4 by 5 people

  • Currently 3.4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Windows live Writer + Paste from Visual Studio

clock February 23, 2009 10:23 by author nazar rizvi

I have been using Windows live writer with the plug-in ‘Paste from Visual Studio’. These make a perfect combination for blogging where in the hassle of formatting the posting is easily overcome. More over you would get the colors and other features of Visual Studio.

Some of the other plug-ins which i use are SnagIt Screen capture and a twitter plugin.

Links:

Paste from Visual Studio plug-in

Currently rated 4.0 by 6 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


ASP.net Interfaces

clock June 2, 2008 08:11 by author Nazar Rizvi

I was going through interfaces in ASP.net and I foung this article named 'Understanding Interfaces and Their Usefulness' by Tim Stall.

You can get to it at: http://aspnet.4guysfromrolla.com/articles/110304-1.aspx

Couple of the examples provided would help anyone kick off... 

Currently rated 2.7 by 3 people

  • Currently 2.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


ASP.net AJAX Text Editor

clock November 16, 2007 06:27 by author Nazar Rizvi

I have been using the FCK Text Editor for almost 2 years, and finally codeplex have come out with a new ASP.NET AJAX Rich Text Editor.

Featurewise it has all the funtionality of FCKeditor; I think tha performance it not upto the previous one, but who cares the AJAX makes it all the more usable.

And it also supports multiple languages. Here is the code plex link.

Currently rated 4.1 by 9 people

  • Currently 4.111111/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Image Slideshow with fading effect

clock November 11, 2007 12:05 by author Nazar Rizvi

I have been trying to use the slideshow control so that the images fade in and fade out. I tried searching various forums out there but there is no actual solution for it. Undecided 

Finally I added up few AJAX animation effects to the slideshow container which would give you the desired effect.

NOTE: This is sort of an hack where in you have to manually time the fading in and out effects and the slideshow timing.

Also since this is continuous javascript this might put a little bit load on the user's browser.

Below is my code:

<script runat="Server" type="text/C#">

[System.Web.Services.WebMethod]

[System.Web.Script.Services.ScriptMethod]

public static AjaxControlToolkit.Slide[] GetSlides()

{

return new AjaxControlToolkit.Slide[] {

new AjaxControlToolkit.Slide("images/Autumn Leaves.jpg", "", ""),

new AjaxControlToolkit.Slide("images/Creek.jpg", "", ""),

new AjaxControlToolkit.Slide("images/Dock.jpg", "", ""),

new AjaxControlToolkit.Slide("images/Forest.jpg", "", "")};

}

</script>

<div>

<asp:Image ID="Image1" runat="server" Width="800px" Style="border: 1px solid black;

width: auto" ImageUrl="images/Creek.jpg" AlternateText="ME" /><br />

</div>

<cc1:SlideShowExtender ID="slideshowextend1" runat="server" TargetControlID="Image1"

SlideShowServiceMethod="GetSlides" AutoPlay="true" ImageTitleLabelID="imageTitle"

ImageDescriptionLabelID="imageDescription" PlayInterval="7000" Loop="true" />

<cc1:AnimationExtender ID="MyExtender" runat="server" TargetControlID="Image1">

<Animations>

<OnLoad>

<Sequence iterations="0">

<FadeIn Duration="10.0" Fps="5" />

<FadeOut Duration="10.0" Fps="5" />

</Sequence>

</OnLoad>

</Animations>

</cc1:AnimationExtender>

Currently rated 4.3 by 10 people

  • Currently 4.3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Two rows of tab headers in TabContainer in Ajax Control Toolkit

clock October 10, 2007 06:27 by author Nazar Rizvi

I had this issue where I wanted more than one row of headers in the TabContainer as I had a large number of panels and was not able to fit them in the page.

Here is the solution. [make sure you download the toolkit with source]

Open the AJAX Control Toolkit's solution by clicking on the solution file inside the toolkit folder.  

Open the file Tabs.css under AjaxControlToolkit/Tabs/Tabs.css

And make the following changes.

/* default layout */.ajax__tab_default .ajax__tab_header {}
.ajax__tab_default .ajax__tab_outer {display:-moz-inline-box;display:inline-block}
.ajax__tab_default .ajax__tab_inner {display:-moz-inline-box;display:inline-block}
.ajax__tab_default .ajax__tab_tab {margin-right:4px;overflow:hidden;text-align:center;cursor:pointer;display:-moz-inline-box;display:inline-block}

Now click on Build -> Build Solution to build the solution.


Use the AjaxControlToolkit.dll under ToolkitTests/Bin folder as your reference from now on.


Add this dll file as reference to your current website and you should have the 2 rows.


 

 

Currently rated 4.1 by 14 people

  • Currently 4.071429/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Special GridView

clock October 7, 2007 05:28 by author Nazar Rizvi

I have been going through the ASP.net forums and many people have had issues with GridViews especially the situation where the user wants to group each row by a particular condition.

There are controls available in the market which solve the issue (only sad part is we need to buy them).

I have used up 2 GridViews and AJAX Control Toolkit's accordion to achieve the required result. I have not done any back-end code, so this enables even a novice developer to create this page. Also I am using the NorthWind database provided by Microsoft.

 

Working Link

Download the source-code

Screenshot:

Code:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CategoryID"                
DataSourceID="getCategories">                
<Columns>                    
<asp:TemplateField HeaderText="CategoryName" SortExpression="CategoryName">                        
<ItemTemplate>                            
<asp:Label Visible="false" ID="labelCategoryID" runat="server" Text='<%# Bind("CategoryID") %>'></asp:Label>                           
<cc1:Accordion ID="MyAccordion" runat="server" SelectedIndex="-1" HeaderCssClass="accordionHeader"                                
ContentCssClass="accordionContent" FadeTransitions="true" FramesPerSecond="30"                                
TransitionDuration="250" Width="500px" AutoSize="None" RequireOpenedPane="false"                                
SuppressHeaderPostbacks="true">                                
<Panes>                                    
<cc1:AccordionPane ID="pane1" runat="server">                                        
<Header>                                            
<asp:DataList ID="DataList2" runat="server" DataSourceID="getNamefromID">                                                
<ItemTemplate>                                                    
<asp:HyperLink NavigateUrl="~/Default.aspx" runat="server" Text='<%# Eval("CategoryName") %>'></asp:HyperLink>                                                
</ItemTemplate>                                           
</asp:DataList>                                        
</Header>                                        
<Content>                                            
<asp:GridView CellPadding="4" ForeColor="#333333" GridLines="None" ID="GridView2"                                                
runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID" DataSourceID="getProducts">                                                
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />                                                
<RowStyle BackColor="#E3EAEB" />                                                
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />                                                
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />                                                
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />                                                
<EditRowStyle BackColor="#7C6F57" />                                                
<AlternatingRowStyle BackColor="White" />                                                
<Columns>                                                    
<asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"                                                        
ReadOnly="True" SortExpression="ProductID" />                                                    
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />                                                    
<asp:BoundField DataField="SupplierID" HeaderText="SupplierID" SortExpression="SupplierID" />                                                    
<asp:BoundField DataField="QuantityPerUnit" HeaderText="QuantityPerUnit" SortExpression="QuantityPerUnit" />                                                
</Columns>                                            
</asp:GridView>                                        
</Content>                                    
</cc1:AccordionPane>                                
</Panes>                            
</cc1:Accordion>                            
<asp:AccessDataSource ID="getNamefromID" runat="server" DataFile="~/App_Data/Nwind.mdb"                                
SelectCommand="SELECT [CategoryName],[CategoryID] FROM [Categories] WHERE ([CategoryID] = ?)">                                
<SelectParameters>                                    
<asp:ControlParameter ControlID="labelCategoryID" Name="CategoryID" PropertyName="Text"                                       
 Type="Int32" />                                
</SelectParameters>                            
</asp:AccessDataSource>                            
<asp:AccessDataSource ID="getProducts" runat="server" DataFile="~/App_Data/Nwind.mdb"                                
SelectCommand="SELECT [ProductID], [ProductName], [SupplierID], [QuantityPerUnit] FROM [Products] WHERE ([CategoryID] = ?)">                                
<SelectParameters>                                    
<asp:ControlParameter ControlID="labelCategoryID" Name="CategoryID" PropertyName="Text"                                        
Type="Int32" />                                
</SelectParameters>                            
</asp:AccessDataSource>                        
</ItemTemplate>                    
</asp:TemplateField>                
</Columns>            
</asp:GridView>            
<asp:AccessDataSource ID="getCategories" runat="server" DataFile="~/App_Data/Nwind.mdb"                
SelectCommand="SELECT [CategoryName], [CategoryID] FROM [Categories]"></asp:AccessDataSource>

 

Currently rated 5.0 by 8 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Installing Apache on Vista - Best Solution

clock October 4, 2007 18:23 by author Nazar Rizvi

The other day I was trying to install PHP and apache server on my Vista machine. As I went ahead it got a little bit complicated and some things didn't work out. Then had to search for stuff online and finally got hold of this article which works fine.

Installing Apache:

Uninstall any previous installations of Apache Web server (Start > Control Panel > Programs and Features).

Turn off your firewall (Control Panel).

Stop User Control Access(UAC). Do this by turning it off on your vista machine.

Get the most recent version of apache from http://httpd.apache.org/download.cgi and put it on your desktop. Rename it to apache.msi

Start > All Programs > Accessories

Right-Click “Command Prompt” and choose “Run as Administrator”

Manually remove directories containing previous apache installations (like C:\Program Files\Apache Software Foundation…)

Change to your desktop folder (At prompt type cd desktop)

Type “msiexec /i apache.msi” on the command prompt.

Run through the Apache installer. I’m running a development server, so I left the domain and computer name blank. Choose the default server on port 80 for all users option. Change the installation directory to c:\apache.

Reboot.

The little Apache feather won’t appear on the task bar under Vista with the present version of Apache (2.2.4). To remove the “error” box that says ‘the operation completed successfully” on startup, go to All Programs > Startup, and remove the Apache item there.
Browse to http://localhost. It should say “It works!” If it doesn’t, check your httpd.conf file by going to All Programs > Apache HTTP Server 2.2.x > Configure Apache Server > Test Configuration. Follow the directions for fixing the configuration file.
Turn your firewall and UAC back on.

Now you can install PHP the same way you did for apache. (Follow the same steps as you would do for Windows XP, just turn off the UAC).

 

 

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Search

About me

I am Nazar Rizvi and I work as a .NET Developer on projects at Geneca. If you need more info you can visit narizvi.com.

Calendar

<<  September 2010  >>
SuMoTuWeThFrSa
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

Archive

Tags

    Categories


    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2010

    Sign in