Jun 21, 2011

India Currency format using Asp.Net

Hello Friends,

I got nice solution.

using System.Globalization;

CultureInfo info = new CultureInfo("hi-IN");
Response.Write(double.Parse("1389000.00").ToString("N2", info));

I hope help to you.

Jun 17, 2011

Use .VB and .CS class file in one website using asp.net

When I was creating my one of the site, I chose to write it in C#. I had a problem with the App_Code folder because I had some code in VB.NET code and some C# code I needed to put in there. I didn't want to rewrite my VB.NET code in the App_Code folder just so I could write the rest of the code for the site in C#.

Luckily, the ASP.NET Team had already thought about just this kind of circumstance. They implemented a way to partition the App_Code folder into sub-folders, one for each set of code files written in the same programming language. Awesome, I didn't have to spend a couple hours converting code from VB.NET to C#!

The below works with ASP.NET 2.0 and later.

Even if you don't use multiple different programming languages for your code files in the App_Code folder, you could use this feature to organize your sets of related code files into sub-folders.

Step 1: Add the following lines to the web.config


<configuration>
<system.web>
<compilation>
<codeSubDirectories>
<add directoryName="VB_Code"/>
<add directoryName="CS_Code"/>
codeSubDirectories>
compilation>
system.web>
configuration>

Step 2: Create a sub-folder in the App_Code folder for each language you want to support.
For Example:
/App_Code/VB_Code
/App_Code/CS_Code

Step 3: Place your VB.NET code in the VB_Code folder and place C# code in the CS_Code folder.

Display India Currency format using JavaScript

function intToFormat(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
var z = 0;
var len = String(x1).length;
var num = parseInt((len/2)-1);

while (rgx.test(x1))
{
if(z > 0)
{
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
else
{
x1 = x1.replace(rgx, '$1' + ',' + '$2');
rgx = /(\d+)(\d{2})/;
}
z++;
num--;
if(num == 0)
{
break;
}
}
return x1 + x2;
}

Jun 6, 2011

Reduce Image File Size Using Asp.Net

//Call to function
imageSave(fluCatImage.FileName, fluCatImage.PostedFile.InputStream, Server.MapPath("~/"), Server.MapPath("../uploadimage/"));


//Implement Function
public void imageSave(string imagename, Stream s, string serverpath, string foldername)
{
if (imagename != string.Empty)
{
System.Drawing.Image image = System.Drawing.Image.FromStream(s);

Bitmap source = new Bitmap(image); //<-- or any other source

Bitmap target = new Bitmap(source.Width, source.Height);
Graphics g = Graphics.FromImage(target);

EncoderParameters e;
g.CompositingQuality = CompositingQuality.HighSpeed; //<-- here
g.InterpolationMode = InterpolationMode.Low;// <-- here

Rectangle recCompression = new Rectangle(0, 0, source.Width, source.Height);
g.DrawImage(source, recCompression);

e = new EncoderParameters(2);
e.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)70);// <-- here 70% quality
e.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionLZW); //<-- here
DateTime MyDate = DateTime.Now;
source.Dispose();
string imgname = DateTime.UtcNow.ToString().Replace(" ", "").Replace("AM", "").Replace("PM", "").Replace("/", "").Replace("-", "").Replace(":", "");
String MyString = imgname + ".jpg";
target.Save(foldername + MyString, GetEncoderInfo("image/jpeg"), e);
// MemoryStream ms = new MemoryStream();
// target.Save(ms, GetEncoderInfo("image/jpeg"),e);
// ms.WriteTo(ms);

g.Dispose();
target.Dispose();
}
}

public static ImageCodecInfo GetEncoderInfo(string sMime)
{
ImageCodecInfo[] objEncoders;
objEncoders = ImageCodecInfo.GetImageEncoders();
for (int iLoop = 0; iLoop <= (objEncoders.Length - 1); iLoop++)
{
if (objEncoders[iLoop].MimeType == sMime)
return objEncoders[iLoop];
}
return null;
}

Jun 3, 2011

Reset AutoIncrement in SqlServer after Delete

I got solution for reset auto identity key to 1.

Just run below query and get result

DBCC CHECKIDENT (TableName, RESEED,1)
hope it will help you