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/