Tuesday, January 24, 2006

Populating a combo box with enumerations

A simple function to populate a combo-box with the enumerations of a particular enum

private void populatecbo(System.Type enum_type, System.Windows.Forms.ComboBox combo)
{
Array arr_populate = Enum.GetValues(enum_type);
combo.DataSource = arr_populate;
}


A cast to type using typeof(enum_type) would be required during the call

Also retrieving the value would be easy

(enum_type)System.Enum.Parse(typeof(enum_type), combo.SelectedValue);

Monday, January 23, 2006

Opening Excel files in a browser in ASP.NET

I was developing a small ASP.NET app and was trying to open an excel file in the browser. After a couple of attempts, I discovered that I was specifying the incorrect MIME type. Upon using the following code I was able to get the excel file to open in the browser:

string fileName = Server.MapPath("HelloWorld.xls");
Response.ContentType = "application/vnd.ms-excel";
Response.WriteFile(fileName);

However, this was opening the file in the same webpage and the back button was not having the desired effect of moving back to the initial page. After some attempts I found a simple way to get that to work correctly:

I declared a class

public class ExcelFile
{
public static string excelFileName;
}

set the static variable to the required filename, redirected the output to another page and used the same code in the page_load event:

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Response.ContentType = "application/vnd.ms-excel";
Response.WriteFile(ExcelFile.excelFileName);
}

Monday, January 16, 2006

VMWare Player

I recently downloaded the latest version of VMWare WorkStation and there was this new utility called VMWare Player that was available for download. This was the coolest virtualization utility that I had ever encountered so far. There were options to open VMC (Microsoft Virtual PC machine configuration) files too. I tried running a couple of machines using that and they ran without any problems.
More information in this regard would be available at :

http://www.vmware.com/products/player/

Saturday, December 24, 2005

AJAX

I read quite a bit about AJAX lately and was amazed by the simplicity and the efficiency that it brought about in web applications. However I realized that this was not something new. The most interesting thing in this is the reduction of postbacks leading to improvement in performance.  About a couple of years back, one of my friends had shown me a online chat demo available at http://www.volano.com which implemented something like this.  The primary reason of the hype for AJAX seems to be because big players like Google have implemented it (gmail)  and there are other ambitious projects like WebOffice.

Tuesday, December 13, 2005

Memory leaks and Undisposed objects

Recently while working on a couple of issues related to memory leaks due to undisposed GDI objects, I came across this excellent post related to using tools to track down and eliminate memory leaks in managed code.

A couple of posts had a great sense of humor

A few good (performance) men
10 reasons why you should subscribe to my blog

Hats off to Rico Mariani.

Sunday, December 04, 2005

CompactFramework and Virtual Machines

I have worked for quite some time on Virtual machines and have also worked on CompactFramework in Dotnet. However I have never been able to run an emulator on a virtual machine using DotNET 1.x. There were many explanations that I had come across in this regard
1. There cant be two layers of virtualization.
2. The WinCE emulator uses the same engine as Virtual PC. (Both have been developed by Connectix). Virtual PC2004 and Virtual Server 2005 are based on this engine and so it is not able to run a copy of the emulator inside itself.

However I did some research on this and was not convinced with either of the reasons. VS.NET 2.0 (Whidbey) allows an emulator to be run from within a Virtual machine. The reason may be that this uses a different emulation engine. Also, when I had tried to run an emulator from a VMWare virtual machine, it failed to run on that too. I feel that I need to gain more gyan on this.
    

Gecko browsers and ASP.NET

ASP.NET has left me high and dry when I try to render web apps on a Gecko browser. I aint sure why this happens, but sometimes scrollbars appear on different parts of the browser, CSS styles appear to have taken a beating. I did a little googling on this and found out that it is not just ASP.NET but IIS also, which may be responsible for this.

The following modifications were suggested in the web.config file

< browserCaps >
< !--Gecko based browsers //-- >
< case match="^Mozilla/5\.0 \([^)]*\) (Gecko/[-\d]+)? (?'type'[^/\d]*)([\d]*)/(?'version'(?'major'\d+)(?'minor'\.\d+)(?'letters'\w*)).*" >
browser="Gecko"
type=${type}
frames=true
tables=true
cookies=true
javascript=true
javaapplets=true
ecmascriptversion=1.5
w3cdomversion=1.0
css1=true
css2=true
xml=true
tagwriter=System.Web.UI.HtmlTextWriter
< case match="rv?'version'(?'major'\d+)(?'minor'\.\d+)(?'letters'\w*))" >
version=${version}
majorversion=${major}
minorversion=${minor}
<case match="^b" with="${letters}" >
beta=true
</case>
</case>
</case>
</browserCaps>

There was another suggestion to use the following in the @page directive
clienttarget="IE5"