Thursday, January 12, 2012

Hosting MVC Application in IIS 5.1 setting

1. Right click on Default Web Site and click Properties
2. Make sure the website or virtual directory is an Application.
3. Set permissions to Scripts Only
4. Click Configuration. Under the Mappings tab, click the Add button
5. You need to insert the path to the file aspnet_isapi.dll. This is most likely C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll.
6. In the Extension field, enter .* .
7. Select All Verbs. Select “Script Engine”. Make sure ”Check that file exists” is not selected.
Click OK at this point.

Wednesday, April 20, 2011

Getting the current row in GridView Row Command Event.

In row command if you want to get the current row or its index, It is not directly possible. There is two way, one is on row created event on the link button(suppose, it is used for row command) save row index in link button command argument attribute.

And get the argument from row command event using e.CommandArgument

But if you want to send another value as a command argument then it creates problem. To solve this just use this code

GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);

Here link button (or any source) that cause to enter in row command event. Now you have selected row so you don’t need any index and directly access any row variable as sample code is given below
Label lblProdId = (Label)row.FindControl(“lblproductId”);

So whole code is just two line. Below I write whole code

GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);

Label myLabel = (Label)row.FindControl("myLabel");

Monday, March 28, 2011

Resize An Image While Maintaining Aspect Ratio in C#

// This allows us to resize the image. It prevents skewed images and
// also vertically long images caused by trying to maintain the aspect
// ratio on images who's height is larger than their width

public void ResizeImage(string OriginalFile, string NewFile, int NewWidth, int MaxHeight, bool OnlyResizeIfWider)
{
System.Drawing.Image FullsizeImage = System.Drawing.Image.FromFile(OriginalFile);

// Prevent using images internal thumbnail
FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

if (OnlyResizeIfWider)
{
if (FullsizeImage.Width <= NewWidth) { NewWidth = FullsizeImage.Width; } } int NewHeight = FullsizeImage.Height * NewWidth / FullsizeImage.Width; if (NewHeight > MaxHeight)
{
// Resize with height instead
NewWidth = FullsizeImage.Width * MaxHeight / FullsizeImage.Height;
NewHeight = MaxHeight;
}

System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);

// Clear handle to original file so that we can overwrite it if necessary
FullsizeImage.Dispose();

// Save resized picture
NewImage.Save(NewFile);
}
source: http://snippets.dzone.com