Keep in touch

you can keep in touch with my all blogs and sites by install this Toolbar...
http://rworldtoolbar.ourtoolbar.com/

Monday, September 29, 2008

Error - GetTypeHashCode() : no suitable method found to override

I found it very useful so I want to it here. I found a need for it while transferring my site from vb.net to C#.

After creating an ASP.NET web form using Microsoft Visual Studio 2005 or Microsoft Visual Studio 2005 Team Suite, I renamed the form from it's default name "Default.aspx" to a more user-friendly name "Order.aspx" within MS VS. After adding more code to the C# code-behind page, I discovered the following line: "public partial class _Default"

Being new to the ASP.NET programming language, I changed the "_Default" to "Order" thinking MS VS had failed to rename items within the code it generates. This caused the following error to display at debug/run time: "GetTypeHashCode() : no suitable method found to override"

There were several other errors displayed as well.

The class names must match between the .aspx and .aspx.cs web pages. Here is what the lines in each file should look like:

In the ASPX source file: %@ Page Language="C#" codefile="FormName.aspx.cs" Inherits="FormName_aspx" %

In the ASPX.CS source file: public partial class FormName_aspx : Page

Once I changed the .ASPX file to match the class name in the .ASPX.CS file, the errors were resolved.

Ref::
http://forums.asp.net/t/1225330.aspx
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/7dbed154-34c6-41e3-b44f-23a594e9ccba/

Saturday, September 27, 2008

GenerateRandomName for images in asp.net 2.0 using c#

public string GenerateRandomName()
{

string allowedChars = "";
allowedChars = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,";
allowedChars += "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,";
allowedChars += "1,2,3,4,5,6,7,8,9,0";
char[] sep ={ ',' };
string[] arr = allowedChars.Split(sep);
string fname = "";
string temp = "";
Random rand = new Random();
for (int i = 0; i < 10; i++)
{
temp = arr[rand.Next(0, arr.Length)];
fname += temp;
}
return fname;
}

just call this like::
string getrandomname = GenerateRandomName;

Happy Coding..!!

Friday, September 26, 2008

code to store and retrieve image from sql server

Image tmpImg = pictureBox1.Image;
System.IO.MemoryStream memBuffer = new System.IO.MemoryStream();
tmpImg.Save(memBuffer, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] output = new byte[memBuffer.Length];
memBuffer.Read(output, 0, (int)memBuffer.Length);
// Write to SQL here

// Read from SQL here
memBuffer.Write(output, 0, output.Length);
tmpImg = Image.FromStream(memBuffer);
pictureBox1.Image = tmpImg;

Friday, September 12, 2008

How to ping a computer using windows application

// Pass host name or IP Address.
public void PingHost(string host)
{
try
{
System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
System.Net.NetworkInformation.PingReply pingReply = ping.Send(host);

MessageBox.Show("Status: " + pingReply.Status.ToString());
}
catch (System.Net.NetworkInformation.PingException e)
{
MessageBox.Show(e.Message);
}
}

private void button1_Click(object sender, EventArgs e)
{
PingHost(textBox1.Text.Trim());
}

Code for Lock Computer, VS 2005, c#

Follwing code is for Lock a Computer. It is nothing but calling of
“ C:\WINDOWS\system32\rundll32.exe user32.dll,LockWorkStation” command. There
are Command for shut down, log off , restart....


using System;
using System.Collections.Generic;
using System.Text;
//using System.linq;
using System.Diagnostics;

namespace r.LockComputer
{
class Program
{
static void Main(string[] args)
{
Process.Start(@"C:\WINDOWS\system32\rundll32.exe", "user32.dll,LockWorkStation");
}
}
}