Tuesday, July 28, 2009

Dock panel in WPF and Databinding

<DockPanel >
<TextBox DockPanel.Dock="Top" Text="TOP"/>
<TextBox DockPanel.Dock="Right" Text="Right"></TextBox>
&l;tTextBox DockPanel.Dock="Bottom" Text="{Binding Path=Name}"/>
</DockPanel>


-----------------------------------
class person
{
string name = "Admin";
public string Name
{
get { return name; }
set { name = value; }
}
}
--------------------------------------
public Window1()
{
InitializeComponent();
person p = new person();
this.DataContext = p;
}
--------------------------------------

Friday, July 3, 2009

How to get Control ID's from websites using C# web browser

ButtonGetID_Click
---------------
MessageBox.Show(webBrowser1.Document.ActiveElement.Id.ToString());
----------------


Insert data to the Fileds
--------------------------

webBrowser1.Document.ActiveElement.InnerText = "smilu";
webBrowser1.Document.GetElementById("Passwd").InnerText = "password";

--------------------------

Click in HTML Buttons
-----------------------------
HtmlElement el = webBrowser1.Document.All["signIn"];
object obj = el.DomElement;
System.Reflection.MethodInfo mi = obj.GetType().GetMethod("click");
mi.Invoke(obj, new object[0]);
------------------------------

Saturday, February 21, 2009

String Encryption

using System.Security.Cryptography;
using System.IO;

static string EncrypData;
static byte[] bytes =System.Text.ASCIIEncoding.ASCII.GetBytes("AbCdEfGh");
private void buttonEncrypt_Click(object sender, EventArgs e)
{
try
{
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateEncryptor(bytes, bytes), CryptoStreamMode.Write);

StreamWriter writer = new StreamWriter(cryptoStream);
writer.Write(textBox1.Text);
writer.Flush();
cryptoStream.FlushFinalBlock();
writer.Flush();

EncrypData = Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
StreamWriter sw = new StreamWriter(@"C:\MyEncryption.DAT");
sw.Write(EncrypData);
sw.Flush();
sw.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void buttonDecrypt_Click(object sender, EventArgs e)
{
try
{
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(EncrypData));
CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateDecryptor(bytes, bytes), CryptoStreamMode.Read);
StreamReader reader = new StreamReader(cryptoStream);

StreamWriter sw = new StreamWriter(@"C:\MyDecrypt.DAT");
sw.Write(reader.ReadToEnd());
sw.Flush();
sw.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}