Search This Blog

Sunday, April 8, 2012

Capture and save active window including taskbar.

try
            {
                
                using (Bitmap imageBmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, Graphics.FromHwnd(IntPtr.Zero)))
                {
                
                    using (Graphics graphics = Graphics.FromImage(imageBmp))
                    {
                        graphics.CompositingQuality = CompositingQuality.HighQuality;
                        graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        graphics.SmoothingMode = SmoothingMode.HighQuality;

                
                        graphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, imageBmp.Size, CopyPixelOperation.SourceCopy);
                        imageBmp.Save("d:\\temp.jpeg",ImageFormat.Jpeg);
                    }
                }
            }
            catch (Exception ex)
            {
                // log the exception

            }

Saturday, April 7, 2012

Authenticating Users With Encryption Of Passwords


BtnLogin_Click()

{ 

string UserId = txtUser.Text.Trim();

Session["UserId"] = UserId;

String Pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text.Trim(),"MD5");

{

            SqlConnection cnn = new SqlConnection(Conn);

            SqlCommand cmd = new SqlCommand("spGetUsers", cnn);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@UserId", UserId);

            cmd.Parameters.AddWithValue("@Pwd", Pwd);        

            SqlDataAdapter ada = new SqlDataAdapter(cmd);

            DataSet ds = new DataSet();

            ada.Fill(ds);

           if (ds.Tables[0].Rows.Count >0)

            {

                 if(Pwd==ds.Tables[0].Rows[0]["Password"].ToString());

                {

                 Response.Redirect("Home.aspx");

                }

                    else

                {

                 Response.Redirect("Loginaspx");

                }

            }

}



While Registering Store The Pwd in this Encrypted Format 
String Pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text.Trim(),"MD5"); 

Both are Applicable MD5 or SHA1 

Currency Convertor using WebServices

Currency Convertor using WebServices 

1)Go To Visual Studio 2010 -> New Project -> Select Asp.NET Web Service Application -> OK 
2)Design CurrencyConvertor.aspx 

We Need 1 Textbox -TxtAmount 
2 DropDownList - DdlFromCurrency , DdlToCurrency 
1 Button - Button1 
1 Label - LblResult 

Design Source of CurrencyConvertor.aspx 


3)Write Code in CurrencyConvertor.aspx.cs 

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Net; 
using System.IO; 
using System.Xml; 


namespace Exchange_Rate_Calculator_WebService 

public partial class Currency_Convertor : System.Web.UI.Page 

Service1 CurrenyConvertorService = new Service1(); 
protected void Page_Load(object sender, EventArgs e) 



protected void Button1_Click(object sender, EventArgs e) 

double CurrencyAmount; 
//Check for a numeric value entered into the Amount textbox 
try 

CurrencyAmount = double.Parse(TxtAmount.Text); 

catch 

LblResult.Text="Please enter a Numeric Value!"; 

return; 


try 

string Result = null; 
string url; 

//Call the web service to get the exchange rate for the two currencies selected by the user 
url = "http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=" + DdlFromCurrency.SelectedValue + "&ToCurrency=" + DdlToCurrency.SelectedValue + ""; 
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 
StreamReader Stream = new StreamReader(response.GetResponseStream()); 
XmlDocument doc = new XmlDocument(); 
Result = Stream.ReadToEnd(); 
doc.LoadXml(Result); 

//Retrieve the conversion rate 
string NewConversionRate = doc.GetElementsByTagName("double").Item(0).InnerText; 
//Convert the conversion rate string to a double 
double ConversionRate = double.Parse(NewConversionRate); 

//Calculate the currency exchange 
double ConvertedAmount = CurrencyAmount * ConversionRate; 
//Display the results on the Default.aspx page 
LblResult.Text = TxtAmount.Text + " " + DdlFromCurrency.SelectedItem + " = " + dblConverted + " " + DdlToCurrency.SelectedItem; 

catch 

LblResult.Text = "Oops..Web Service Not available. Try again later"; 











4) Enter the Currency Amount you want to convert and check the result.