Archive for the ‘.NET articles’ Category

Serialize and Deserialize to JSON from ASP.NET

April 23rd, 2010 by Sameer | No Comments | Filed in .NET articles

Its very easy to serialize an object to .NET
Simply create some object, normally a custom class with some attributes.
Normally you have a list of these and you want to serialize to JSON to use it from client side code.

If you do the following

var s = new System.Web.Script.Serialization.JavaScriptSerializer();
string resultJs = s.Serialize(result);

you will end up with a JSON array that you were looking for:

[
  { "Desc" : "Corn 100 ",
    "ItemNo" : "123456",
    "OriginalQty" : 50,
    "Qty" : 50,
    "UnitPrice" : 10.21
  } ,
  { "Desc" : "Ice 100 ",
    "ItemNo" : "323456",
    "OriginalQty" : 50,
    "Qty" : 50,
    "UnitPrice" : 10.50
  } ,
  { "Desc" : "Meat 100 ",
    "ItemNo" : "423456",
    "OriginalQty" : 50,
    "Qty" : 50,
    "UnitPrice" : 10.11
  } 

]

However if you try to deserialize this back into an object by running

var json = new System.Web.Script.Serialization.JavaScriptSerializer();
var result = json.Deserialize<ShoppingCartItem[]>(jsonItemArray);
    

You will get a NULL type Exception.

The solution is to create a simple resolver as follows

    using System;
    using System.Web;
    using System.Web.Compilation;
    using System.Web.Script.Serialization;

    namespace XYZ.Util
    {
        /// <summary>
        /// as __type is missing ,we need to add this
        /// </summary>
        public class ManualResolver : SimpleTypeResolver
        {
            public ManualResolver() { }
            public override Type ResolveType(string id)
            {
                return System.Web.Compilation.BuildManager.GetType(id, false);
            }
        }
    }
    

2) Use it to serialize

    var s = new System.Web.Script.Serialization.JavaScriptSerializer(new XYZ.Util.ManualResolver());
    string resultJs = s.Serialize(result);
    lblJs.Text = string.Format("<script>var resultObj = {0};</script>", resultJs);
    

You will get something like the following this time (note new __type included this time)

[
  {
    "__type":"XYZ.Data.Entities.ShoppingCartItem, XYZ.Data, Version=1.7.1.0, Culture=neutral, PublicKeyToken=null",
    "Desc" : "Corn 100 ",
    "ItemNo" : "123456",
    "OriginalQty" : 50,
    "Qty" : 50,
    "UnitPrice" : 10.21
  } ,
  {
    "__type":"XYZ.Data.Entities.ShoppingCartItem, XYZ.Data, Version=1.7.1.0, Culture=neutral, PublicKeyToken=null",
    "Desc" : "Ice 100 ",
    "ItemNo" : "323456",
    "OriginalQty" : 50,
    "Qty" : 50,
    "UnitPrice" : 10.50
  } ,
  {
    "__type":"XYZ.Data.Entities.ShoppingCartItem, XYZ.Data, Version=1.7.1.0, Culture=neutral, PublicKeyToken=null",
    "Desc" : "Meat 100 ",
    "ItemNo" : "423456",
    "OriginalQty" : 50,
    "Qty" : 50,
    "UnitPrice" : 10.11
  } 

]

3) Use it to deserialize

    System.Web.Script.Serialization.JavaScriptSerializer(new XYZ.Util.ManualResolver());
    var result = json.Deserialize<ShoppingCartItem[]>(jsonItemArray);
    

References: Comment by Manuel Abadia on ASP.NET AJAX Extensions Internals – Web Service Proxy Generation

Flesk Viewstate Optimizer Documentation

March 1st, 2010 by Sameer | 4 Comments | Filed in .NET articles

I came across this excellent looking tool Flesk ViewState Optimizer but was not able to find any details or documentation on it.  Apparently the tool used to be commercial but now its free!  I was able to dig up some history on it

Flesk.ViewStateOptimizer is a unique technology that overrides sending ViewState object to your client’s browser! This means that your client’s browser will no longer receive those large hidden field values, which thus reducing downloading time. Instead, Flesk.ViewStateOptimizer saves the page’s Viewstate hidden field to a file, on the server side, speeding up processing time, downloading time and data.

Combining Flesk.ViewStateOptimizer and Flesk.Accelerator,
you can benefit from reducing downloading data and downloading time up to 30 times faster! No other components
do the same or give the same results!

Flesk.Accelerator and Flesk.ViewStateOptimizer are now released with versions
targeted for the .NET Framework v2.0

 

How it works?

Flesk.ViewStateOptimizer has several viewstate optimization possibilities that can be set through the web.config file.
From viewstate data compression to saving viewstate on server farms, anything can be possible. This means that Flesk.ViewStateOptimizer can persist values using server side Sessions or files saved on shared locaton accessible by a server farm, or by using common viewstate hidden field value on client side, with the ability to compress data.

There are 2 ways to setup Flesk.ViewStateOptimizer on your web application or .Net project:

  1. In all your codebehind, instead of inheriting your class with
    System.Web.UI.Page, change the inheritance to Flesk.Accelerator.Page.
    If you use script block codebehind, use the following lines:

    &lt;%@ Page  Language=&quot;C#&quot; Inherits=&quot;Flesk.Accelerator.Page&quot; %&gt;
    
  2. Flesk.ViewStateOptimizer is designed to meet the requirements of customers that are unable to change
    the base class of their pages.
    As such, Flesk.ViewStateOptimizer provides static methods that allows calling the viewstate procedures
    from within any page class.

    If you have access to the source of your base class, just add the following lines to the code:

    protected override void  SavePageStateToPersistenceMedium(object viewStateBag)
    {
       Flesk.Accelerator.Page.SavePageStateToPersistenceMedium(this, viewStateBag);
    }
    
    protected override object LoadPageStateFromPersistenceMedium()
    {
        return Flesk.Accelerator.Page.LoadPageStateFromPersistenceMedium(this);
    }
    

    If you are using precompiled code you’ll have to edit your aspx files. If at all possible, add the following

    snippet to your aspx file:

    protected override PageStatePersister PageStatePersister
    {
      get
      {
        return Flesk.Accelerator.Page.GetPageStatePersister(this);
      }
    }
    

 

Flesk.ViewStateOptimizer can use different storage methods:

  • save to file (saves ViewState into a file, server side)
  • Session (saves ViewState into a Session variable, server side)

  • Default (default ViewState saving method, sends hidden fields to client side)

Other parameters are:

  • depending on the storage method setting, Flesk.ViewStateOptimizer can be set to compress viewstate value,
    so that it can be significantly smaller than the original value
  • the request behaviour of viewstate can be set to be generated on the first request to a page and then
    reused in the following postbacks, or to be generated on each request to a page.
    A common scenario where viewstate set to be generated on each request can be usefull is in Content Management
    frameworks:
    page loads up some controls on postback based on some state stored in hidden input values, handles events
    and as a result of those actions purges the control collection and loads new controls.
    Standard Flesk.ViewStateOptimizer configuration persists the Viewstate using the same GUID as the original
    page.
    If the user then hit’s refresh (F5) in the browser, the data is posted again, the framework loads up it’s
    controls based on the original state but the viewstate value now matches the new controls. This also happens
    with any change to the viewstate between postbacks, when users back up or use refresh in their browsers.

    The solution was to make Flesk.ViewStateOptimizer generate GUID’s each and every time the viewstate is persisted.
    Only then is the viewstate truly unique for each page.

 

Features

V1.0

  • Reduces downloading time of your website or web application, by not sending back the page’s Viewstate
    hidden field.
  • This component is setup individually. It is not shared by all the webserver’s websites, but only by
    your website or webapplication. This means that you can install it in your hosting account without changing
    any webserver’s configuration.
  • Runs on .NET Framework v1.1 and v2.0. No configuration required. Only a few lines on your web.config
    file is all you need to change.
  • Greatly reduces bandwidth traffic from your webserver, reduces Posted data from your client’s browser,
    and speeds up your web application!
    Supported by WebFarms

V1.2

  • Compresses the ViewState value. This means that ViewState is sent and returned to/from client’s browser
    or saved into local file, on server, compressed, thus reducing ViewState’s value length and increasing
    speed even more!
  • This release of the Viewstate Optimizer is designed to meet the requirements of
    customers that are unable to change the base class of their pages.
  • The Flesk.Accelerator.Page class now provides two static methods that allow calling the viewstate

    procedures from within any page class.

  • ViewState files can now be persisted on shared location accessible by all servers in a server farm.

From Archive.Org

Not sure what happened to the company but glad they decided to give their product for free now! (GPL license)

Edit Aug 12, 2010

Web.Config Requirements

To use this, here is what you put in Web.Config between <configuration> and </configuration>

  &lt;Flesk.NET&gt;
    &lt;!--
		The StorageMethod parameter sets the ViewState's storage type.
		Possible values are :

			- File (saves ViewState into a file, server side)
				- StoragePath must specify a write enabled server path ( ~ means site root path)
					If StoragePath is a web path (i.e.: \\MachineName\Dir), when used in webfarms,
					please add the following line under &lt;system.web&gt;
					&lt;identity impersonate=&quot;true&quot; userName=&quot;domain\username&quot; password=&quot;userpass&quot;/&gt;

			- Default (default ViewState saving method, sending hidden fields to client side)

			- Session (saves ViewState into a Session variable, server side)

			- SqlServer (saves the ViewState into a database table)
				- ConnectionString specifies the database connection.
				- TableName specifies the table in the database where the records will be stored.

		New Option :
			Compressed=&quot;true&quot; or Compressed=&quot;false&quot;
			this will compress the ViewState if StorageMethod is Default or File.
			so the ViewState's value will be significantly smaller than the original value.
			Compression method is not suported by StorageMethod=&quot;Session&quot;

		--&gt;
    &lt;ViewStateOptimizer
			PersistenceHandler=&quot;Flesk.Accelerator.SessionViewstatePersister, Flesk.Accelerator&quot;
			StorageMethod=&quot;SqlServer&quot;
			StoragePath=&quot;~/Files/Logs&quot;
			ConnectionString=&quot;Server=...;Database=...;Uid=...;Pwd=...
			TableName=&quot;app_ViewState&quot;
			Compressed=&quot;false&quot;
			RequestBehavior=&quot;EachLoad&quot;
			ViewStateCleanupInterval=&quot;01:00:00&quot;
			/&gt;
  &lt;/Flesk.NET&gt;

Between <configSections> and </configSections> put the following:

    &lt;sectionGroup name=&quot;Flesk.NET&quot;&gt;
      &lt;section name=&quot;ViewStateOptimizer&quot; type=&quot;Flesk.Accelerator.Viewstate.ConfigHandler, Flesk.ViewState&quot; /&gt;
    &lt;/sectionGroup&gt;

Between <httpModules> and </httpModules> you can put

			&lt;!--
			This HttpModule provides automatic cleanup of viewstate files
			on the start of each session, thus requiring
			the SessionStateModule to be installed as well.
		  --&gt;
			&lt;add name=&quot;ViewstateCleanupModule&quot; type=&quot;Flesk.Accelerator.Viewstate.CleanupModule, Flesk.ViewState&quot;/&gt;
		&lt;/httpModules&gt;

LINQ to Entities Create Function Import Scalar Value Missing

April 9th, 2009 by Sameer | No Comments | Filed in .NET articles

LINQ to Entities seems really great. It can save you a lot of time in writing unnecessary db connection code, improve the performance many fold, only connect to the db when required (lazy loading), and easy concurrency handling for you.

However there is a missing feature which I found out the hard way. If you try to do a ‘Create Function Import’ and it returns a scalar, the code will not be automatically generated, due to ‘lack of time’ from the MS Team:

MSDN Forums – See the post by Noam.

So basically, you are handicapped! Either write the code yourself or just do it the old fashioned way

Read Pro ASP.NET 2.0 in C# free

November 11th, 2008 by Sameer | No Comments | Filed in .NET articles

Due to a recent agreement between Google and some book publishers, they are going to publish a large number of books online (limited content depending on each publishers agreement).

So you can now read Pro ASP.NET 2.0 C# for free online (a large chunk of it)!  Click the link for more.  This book is jam packed (1000 pages+) with well-written details on everything under the sun in .NET 2.0.  I was in particular looking for SQL Cache Dependency information which I found in there.

Apparently in SQL Server 2000, Cache Dependency is done on a table basis, you cannot have it dependent on a certain condition (for example select * from CONTACTS where location=’canada’).  If any data at all changes inside CONTACTS then the cache is considered invalidated and you will need fresh data.   Lots of improvements in SQL Server 2005 boys….

Automated .NET testing with WatiN

October 20th, 2008 by Sameer | No Comments | Filed in .NET articles, Software Engineering

This software is super cool.  WatiN – Automated Web Application Testing!

Here’s how you can use it.  Download it.  Download the test recorder (it’s not perfect, but its pretty good).  Create a trivial test case so you know it’s working.  Then build on that test case.    It will output code for NUnit, MBUnit, or even VS2005Test

Load up your VS IDE, then execute it from Visual Studio 2005 or 2008 Test Runner.    It will give you the results right there!  Super cool or what??

With this framework I was able to create some pretty simple test SUPER fast.  – Login test, check for correct page loaded.   Then I tested some shopping cart logic (adding items, removing items, clearing cart.)

In conclusion you can effectively create tests with WatiN.  Give it a try.  It’s compatible with practically every testing framework (including Fitnesse) that you probably use.

Tags:

Updating Your Web.Config From Each Build with CruiseControl

June 17th, 2008 by Sameer | No Comments | Filed in .NET articles, Software Engineering
Let’s say you have CruiseControl.NET all set up nice and hunky dory.  Now you love the fact that it labels your each build, and you want to somehow show that from your project.  Here is how you can get your CruiseControl.NET project build number into your Web.Config.  This concept can be applied to update any file.
It’s super easy. You will need to add an exec block to your ccnet.config
<exec>
<!-- Auto increment web.config build number -->
<executable>E:\Userdata\CruiseControl\Tools\MergeWebConfigValues.exe (my custom tool)</executable>
<buildArgs>"E:\Program Files (x86)\CruiseControl.NET\server\Main.state" e:\userdata\cruisecontrol\Dev_Main\Web.config</buildArgs>
<baseDirectory>e:\userdata\cruisecontrol\Dev_Main</baseDirectory>
<buildTimeoutSeconds>15</buildTimeoutSeconds>
</exec>
 Now all you need to do is write the MergeWebConfigValues.exe
What does it do?
1. It reads the CCNET state file (provided by argument 1) and grabs the last label from there. (The state file is an XML file)
2. It then goes and writes to your Web.Config and updates the build number in there. (or writes to any specified file you like)
Lastly, update your code to read this value by adding some version or about page to read your Web.Config
You now instantly know what version your code is.

Unit Testing on Your Database

May 22nd, 2008 by Sameer | 2 Comments | Filed in .NET articles, Software Engineering

When unit testing on your database, you will run into a common problem.

Rolling back.

So you want to do some unit tests, and then you want to reset your database back to the nice squeaky clean version that doesn’t have half failed unit tests.

So how can you do this?

There are many ways to achieve this.

The best way I found (requires Win XP SP2 or Windows Server 2003) is to use Roy’s Unit Testing Rollback Attribute.  Simply inherit his class, add a "DataRollback" attribute, and you are good to go.  Using some complicated Interception logic and Enterprise Services (COM+) it rolls back all the database work that was done.  It’s super easy to implement.  Here is some sample code that shows you just how easy it is.  You just have to download XtUnit (an extension to NUnit) to do this. (Full source code available)

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using TeamAgile.ApplicationBlocks.Interception.UnitTestExtensions;
using NUnit.Framework;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

namespace DBTest
{
    ///<summary>
    /// Test roll back functionality.
    ///</summary>
    [TestFixture]
    public class RollbackTest : ExtensibleFixture
    {
        [Test, DataRollBack]
        [Category("Database")]
        public void TestInsert()
        {
            //this method will be performed inside a COM+ transaction
            //this requires windows XP SP2 or better
            //Windows Server 2003 works as well.

            string strCnn = "your_conn_string";
            Guid random = Guid.NewGuid();
            string sqlI = string.Format(@"insert into log4net (message,date,thread,level,logger) values ('{0}',getdate(),'{1}','Debug','Test')", random.ToString(), System.Threading.Thread.CurrentThread.GetHashCode());
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.Text, sqlI);

            string sqlS = string.Format(@"select count(*) from log4net where message='{0}'", random.ToString());
            int rowcount = (int)SqlHelper.ExecuteScalar(strCnn, CommandType.Text, sqlS);
            Assert.That(rowcount > 0, "Cannot find {0}", random.ToString());
        }
    }
}
This test passes successfully.  What does that mean? The insert and select worked perfectly fine.  After that, I did a query and found the database to be clean.  So the rollback worked too.
There are also other ways to skin this cat (i.e. to achieve this goal).  One is to use Spring Framework and extend their Unit Testing class (AbstractTransactionalSpringContextTests), and they will handle rolling back everything.  Here is an article on this topic, but unfortunately I was not able to make it work for me due to some odd reason.  Here’s hoping you have better luck.  If you don’t have any transactions, and your code is wired to use Spring, it’s still also very easy, you just need to call TransactionManager.Rollback.
You can also try to achieve this using Nested Transactions if you have existing transactions implemented via Spring.  But then you have to set up checkpoints and stuff like that. 
I have some other ideas on how to achieve this that I will post later, God willing.

PHP VS. ASP.NET

May 8th, 2008 by Sameer | 80 Comments | Filed in .NET articles, Work Related
This is a very shallow comparison of my experiences with PHP and ASP.NET
Don’t take this as a religious war or something, the idea is just some basic comparison.
 
Here is a summary: If you are choosing which technology to use to build an application, use .NET. You will get more bang for the buck. With the same effort you will be able to build a much more rich user interface. 
 
My Disclaimer: Keep in mind there are a lot of great libraries and tools for PHP which I never got to use, I just had a simple PSPad text editor and my handy PHP web site.  I really wanted some “Intellisense” style code completion but I could not get it to work with PHP since I couldn’t find a decent IDE (i.e. editor)
 
However, it all depends on your requirements. For example, if you are selling something that most of your customers will be on a shared linux hosting environment, then why would you use .NET ? A good example is the software Clipshare, which is a clone of Youtube. The sites purchasing this product are mainly shared hosting customers who have PHP but not .NET. And Mono (.NET port on Linux) is not yet stable or popular enough to use.
 
I did some PHP programming before I started doing .NET fulltime. Before then I couldn’t say much about it, but after working with .NET for a few years now, I have much to say.
.NET does a very good job in handling the whole life cycle. With PHP you have to do it manually.   For example, there is no such concept of “Postback” with PHP. This is such a basic thing that you can easily check with .NET to see if the page has been submitted and what button was pressed. For example if your “btnSubmit” was pressed, it will call btnSubmit_Click. With PHP, you have to do this manually. Not to mention how mish mashed your PHP page can be in terms of mixed code and style/HTML elements.

How about caching? I wanted to implement caching with PHP and I had a fun time, I had to check if the cached output file existed, and then if so, then check how old it is, and so on… Yeah okay again maybe there are some nice components already done for this, but I didn’t have to look very hard to do it with .NET, I simply added a CacheDependency on an XML file (or whatever the case was), and BOOM! It regenerated the file whenever necessary.
 
How about reusable components? With .NET you can create ASCX (Custom Controls) that you can place within a page that expose certain properties and the control itself maintains its state, can have buttons, etc, etc.

How about master pages (i.e. templates) in .NET? Again, super cool reusability! You can create pages with repeatable parts, with headers, footers, all sorts of fun stuff.

I can go on and on…  but in general, the more I use .NET, the more impressed I am with it. However, what makes it not-so-practical is how expensive Windows Server hosting is.  In summary .NET kicks butt!
 
Update Oct 8 2008

 
I wanted to add some more meat to this article based on the comments below

I mentioned that getting Windows Server hosting is more expensive.. However, lets look at this in perspective.  What’s more expensive – server cost, or development cost?  Development cost in most cases far outweighs any particular savings of a Windows license.  What this means is even if your application takes two or three times as long to write, then you have lost any potential savings from running a "free" linux box. 

Also, I would like to hear about how to unit test with PHP. 

.NET offers unit testing via many different frameworks, NUnit probably being the most popular right now.   I would like to know how can I unit test in PHP?  There is also an extension for NUnit available called NUnitAsp that allows me to test my interface.  Another notable extension for Nunit is an automatic database rollback.  SWEET!  More details to come as time goes by.

Manage your transaction chaos with Spring Framework

April 30th, 2008 by Sameer | No Comments | Filed in .NET articles

Spring is a popular framework available in Java.  It has also been published in .NET and is called Spring.NET

This framework is huge, but what I wanted to focus on is the section that deals with transaction management.

If you have ever worked with Transactions, (say SQLTransactions), you would realize how messy it can be when you have to keep your connection open and pass around a transaction to many different functions that are making updates or queries, and then you might make a small little change and find out you forgot to use the transaction object and you caused a deadlock!

How can you fix this?  By having a generic transaction/connection object?  Well, that’s one way.. but how about using the Spring.NET framework to deal with the transactions?

Spring.NET allows you to specify when you need a transaction, and you would begin and end the transaction.  However, when you do the actual database calls, you would not pass any connection string, it would automatically use the transaction in process if there is one, or if not needed then it would use a regular connection and disconnect after the query is complete.

Here is a code snippet to demonstrate programmative transaction management, taken from the Spring.NET source code (yeah its open source!)

 

[Test]
        public void ExecuteTransactionManager()
        {
            DefaultTransactionDefinition def = new DefaultTransactionDefinition();
            def.PropagationBehavior = TransactionPropagation.Required;

            //TODO change to property of name TransactionStatus...
            ITransactionStatus status = transactionManager.GetTransaction(def);

            int iCount = 0;
            try
            {
                iCount = (int)adoOperations.ExecuteScalar(CommandType.Text, "SELECT COUNT(*) FROM TestObjects");
                /*
                IAdoCommand cmd = new AdoCommand(dbProvider, CommandType.Text);
                cmd.CommandText = "SELECT COUNT(*) FROM TestObjects";
                iCount = (int)cmd.ExecuteScalar();
                */

                //other AdoCommands can be executed within same tx.
            } catch (Exception e)
            {
                transactionManager.Rollback(status);
                throw e;
            }
            transactionManager.Commit(status);
            Assert.AreEqual(2, iCount);

        }

As you can see from this code, the adoOperations.ExecuteScalar does not have any connection string passed to it.  Same thing with ExecuteDataSet, and so on. 

This actually saves you a lot of headache, as you just have to make sure you use the spring DataOperations object.  The easiest way to implement this on a ASP.NET site is to put these objects as a static variable and initialize them on Application_Load.  Just an idea but it should work. 

 If you want to do more digging, Spring.NET has tons of stuff, it seems to mostly focus on Dependency Injection and loose coupling of code from objects from the data layer.  I really like it and I recommend you give it a shot.

It’s proven itself in Java and I think this framework is going to prove itself in .NET as well.  At the very least the source code is a prime example of a clean object oriented well designed application with full unit tests and sample code, XML documentation, thorough use of interfaces and inheritance, and even ORM (object relational mapping) using NHibernate (again a popular Java framework which has come into .NET)

 Update: I called this "declarative transaction management", actually its "programmative transaction management". – FIXED

Convert your site from VB.NET to C#

February 12th, 2008 by Sameer | 2 Comments | Filed in .NET articles

If you are tired of the headaches of using VB.NET code, and want to convert it to C#.. Here is a nice way to do it and get the comments too. 

Why would you do that?  Well if I have to explain to you, then you probably don’t need to do it.  One big reason for me is that VB.NET does not support multi line strings.  You have to keep putting " & _  at the end of each line making it very difficult to go back and forth from another program with strings.  You could technically create a tool to do this for you but that’s so silly.   Another thing is I really like using ?? operator in C#, for example txtLocation.Text = (GetLocation() ?? "").ToString() will ensure that even if SomeFunction returns null, this will always give you at least empty string..  I like to use this in cases where I am getting null and its a text box I am setting the text for.

Another reason is that VB.NET code doesn’t force you to type your variables properly, so everything is an object unless you specify, or unless you put on Option Strict

One way to do it is to use Reflector + Code generation add-in, but you will lose the comments and maybe even variable names because it uses the intermediate language (IL) from the DLL to re-make the source, so it’s pretty useless to do it this way if you want to keep your code in the long run.

The way I like is to use a site such as http://labs.developerfusion.co.uk/convert/vb-to-csharp.aspx

Keep in mind I know there are other tools available that you can pay for, and some that are free too, but this is a quick and easy way to do it at work without requiring any installation.

Once you perform the conversion, the code will still have some things that need to be manually converted.
One thing is this site does not compile the code, so it does not know if the VB code .Rows(5) is actually a function call called Rows with a parameter 5, or its an array index [5].  So you will need to fix these manually.

Same thing with Tables[], Session[], etc.
Sometimes with VB code you will see .Item being used when no such thing exists in C#, you just use the square brackets to get the item directly such as .Rows.Item(5) in VB.NET is equal to .Rows[5] in C#

Here is how you can search and replace these with a regular expression.

Search: \({(["|a-z|A-Z|,|0-9|\:|\.|_])+}\)

Replace: [\1]

You have to do this manually and confirm each one.. Or make it more smart by searching for keywords such as QueryString, Cookie, Value, etc.. and replace all, then do the rest manually

And again if you want to do them all at once, I wold recommend improving this search to find Rows, Tables, etc.. Also if you have declared an instance of a DataRow object or any other array type object, you will need to search for those as well.
 
Keep in mind its not perfect.  For example I did not put any numbers in my search, so it will miss some of the results.  You might need to tweak it a bit and add |0-9 to the first set of brackets which means OR 0-9

The next thing is that functions such as .InStr are not supported directly from C#, you need to call Microsoft.VisualBasic.Strings.InStr(…)   The code converter will automatically do this, but you need to add using Microsoft.VisualBasic.Strings to the top of your class file.

There are a few more things I could mention, but just try it out and see how it goes.

Here is a few more things
1) "my string" & " is very long" will give an error while converting. Before you run the converter, replace these & in your VB code with + instead.
2) the functions that have handles such as lstItems_SelectedIndexChanged(…) handles lstItems.SelectedIndexChanged need to be taken care of by putting either an event in the ASPX page in the <DropDownList OnSelectedIndexChanged="lstItems_SelectedIndexChanged"

Also, they might be private, so you need to make them protected.  Here’s a regexp to start you off:
find: {(protected|private)} void {(lnk|lst)}
replace with: public void \2

3) Functions that have optional parameters need to be taken care of.  An easy way to take care of this is to create another function that calls the second one that passes the default value with the same name. That easy!

By the way, since I am not regularly writing here, I would suggest you subscribe to my feed so you can get an update when I post a new article.