Sunday, February 14, 2010

Convert image to icon in asp.net

string filename, newfilename;
filename= "E:/..../images/window.jpg"; // your image location
newfilename= Path.ChangeExtension(filename, ".ico");
using(Bitmap bitmap = Image.FromFile(filename, true) as Bitmap)
{
using (Icon icon = Icon.FromHandle(bitmap.GetHicon()))
{
using (Stream iconfile = File.Create(newfilename))
{
icon.Save(iconfile);
Response.Write("Converted - " + newfilename);
}
}
}

Note: Get an icon file n the same folder of image with extension'.ico', it may not work properly,
if the file size morethan 120X120. Try to choose small images.

Friday, February 12, 2010

Add an Existing silverlight Project to website

Hai,
To add an existing silverlight project to a website.
1) First we create / select a website.
2) file- Add- Existing Project- select our silverlight project
3) Delete the 'ClientBin' folder if there exist, note that if you have other files/folders than '.xap' file, don't forget to replace it temperly to other place.
4) "Rightclick" on the website- AddNewItem- select silverlight project template,
Show window with two option buttons, Click 'Use an existing silverlight project in this solution'. A combo box near it become enabled and show the silverlight project sin this solution(if you don't get a project go to step (2)).
5) You will get a 'ClientBin' folder and get the '.xap' file in it.

Note: View discussions about this topic: http://k-mug.org/forums/t/1400.aspx

Add new silverlight project to website

Hai,
We can create silverlight project in two ways:
1) Create new project; New- project- silverlightproject
2) create a website and add a new silverlight project to it;
create new website-> "rightclick" on website 'Add Newitem'- select silverlight project(create/ select new folder to hold the silverlight project, it is good to create a folder in the website folder)- click ok
Note: Get a 'SilverlightTestpage.aspx' page which includes and show the silverlight '.xap' file output. '.xap' stores in'ClientBin' folder, if you want to show images, it ease to create a folder under 'Clientbin' folder and copy the images to it.
Note: After closing your programming, you may get some problems to open recently closed silverlight application, then you should follow the link below http://jineshrev.blogspot.com/2010/02/add-existing-silverlight-project-to.html View discussions about this topic: http://k-mug.org/forums/t/1396.aspx

Wednesday, February 10, 2010

Return datatable from Webservice

Hai,
[WebMethod]
public DataTable TestDatatable
{
DataTable dt = new DataTable("AddressDatatable");
dt.Columns.Add("Name",typeof(System.String));
dt.Columns.Add("Address", typeof(System.String));

DataRow dr = dt.NewRow();
dr["Name"] = "Jinesh";
dr["Address"] = "RevathiBhavan";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Name"] = "Retheesh";
dr["Address"] = "RetheeshBhavan";
dt.Rows.Add(dr);
return dt;
}
Client code:
private void button1_Click(object sender, EventArgs e)
{
helloservice.Service1 service = new WindowsFormsApplication1.helloservice.Service1();
DataTable dt = service.TestDatatable();
}
Note: If you don't give datatable name while declaring it may not not work properly.

Tuesday, February 9, 2010

Show photos in silverlight

//// .xaml



//// .xaml.cs
private void btn1_Click(object sender, RoutedEventArgs e)
{
show.Children.Add(displayalbums());
}
public Canvas displayalbums()
{
show.Children.Clear();
Image img; int j = 0; double k = 1; int i;
Canvas c = new Canvas();
c.SetValue(Canvas.LeftProperty, 20.0);
for (i = 0; i < img =" new" height =" 100;" width =" 110;" src =" new" imgsource =" new" source =" imgSource;"> 3)
{ j = 0; k += 180.0; }
}
show.SetValue(Canvas.HeightProperty,(pagecounter(25))*180.0);
return c;
}
public int pagecounter(int n)
{
int i, r;
r = n % 4; // (4) denotes no. of items in each line
i = n / 4;
if (r > 0)
{ n = i + 1; }
else
{ n = i; }
return n;
}
Note: Make sure that your client bin directory contains the older 'images' and
all the images in that directory

Monday, February 8, 2010

Login program in silverlight/ silverlight database connection

Dears,
Here a sample program to log in into a website using silverlight ....
We can't connect a database directly with silverlight, we use webservices to connect a silverlight
with database.
////silverlight
using System.Windows.Browser;
using System.Windows.Data;

using System.ServiceModel;
using SilverlightApplication.ServiceReference1;

private void btnlogin_Click(object sender, RoutedEventArgs e)
{
if (txt1.Text != "" && pwd.Password != "")
{
services.checkLoginCompleted += new System.EventHandler(logincheckcompleted);
services.checkLoginAsync(txt1.Text, pwd.Password);
}
else { MessageBox.Show("Username and Password shouldnot be blank"); }
}

public void logincheckcompleted(object sender, checkLoginCompletedEventArgs e)
{
if (e.Result != 0)
{
App appeg = (App)Application.Current;
appeg.clientid = Convert.ToInt32(e.Result);
//It's alternative for session, we can re-use the app.xaml variable in page1.xml also
Page1 p = new Page1();
this.Content = p;
}
else
{
MessageBox.Show("Invalid User Credentials");
}
}
////Webservice
[WebMethod]
public int checkLogin(string username, string password)
{
int retvalue=0;
retvalue =(int) frmclass.GetDBValue("select clientid from clientdetails where username='" + username + "' and password='" + password + "'");
return retvalue;
}
////class- here all database related functions lies.

public object GetDBValue(string sqlQuery)
{
object TheValue;
TheValue = 0;
OpenConnection();
db_Command.Connection = db_Connection;
db_Command.CommandText = sqlQuery;
db_Command.CommandType = CommandType.Text;
db_Reader = db_Command.ExecuteReader();
if (db_Reader.Read())
{
if (db_Reader[0] == null)
{ TheValue = 0; }
else
{ TheValue = db_Reader[0]; }
}
CloseConnection();
return TheValue;
}
public void OpenConnection()
{ try
{
if (db_Connection.State != ConnectionState.Open)
{ db_Connection.Open(); }
}
catch (Exception)
{ }
}
public void CloseConnection()
{
if (db_Connection.State != ConnectionState.Closed)
{ db_Connection.Close(); }
}

Top five mistakes of .Net developers

Dears,

Look the following link to read top five mistakes of .Net programming.

http://amazedsaint.blogspot.com/2010/02/top-5-common-programming-mistakes-net.html

Note: This is the views from the blog: http://amazedsaint.blogspot.com/