tag:blogger.com,1999:blog-78776302386648265012024-03-05T04:54:57.259-08:00Waleed ElkotWork Smarter Not HarderWaleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.comBlogger23125tag:blogger.com,1999:blog-7877630238664826501.post-38002523243088134292009-08-12T04:33:00.000-07:002009-08-12T07:43:29.339-07:00How To: Hash Data Using MD5 and SHA1There are two types of Encryption:<br /><br /><strong>1- One way Encryption:</strong><br />take input data and encrypt it, and there is no way to decrypt it again to get the source data and the good sample for one way encryption is MD5.<br /><br />also the good sample for one way encryption (SQL Server Membership), it's store passwords encrypted and there is nno way to get the original Password.<br /><br />only we can compare between the source you enterd and the hashed data.<br /><br /><strong>2- Two way Encryption:</strong><br />take input data and encrypt it, and in another side we can take encrypted data and decrypt it again using the same algorithm.<br /><br /><strong>Sample:<br /></strong><span style="color:#000099;">http://waleedelkot.blogspot.com/2009/02/encryption-and-decryption-using-c.html</span><br /><br />today I'll talk about MD5 and SHA1 and I'll Present a sample code.<br /><br /><strong>Namespace</strong>: System.Security.Cryptography<br /><br /><em>the below method will return MD5 hashed string:</em><br /><br /><span style="color:#3333ff;">private string GetMD5HashData(string data)<br />{<br />MD5 md5 = MD5.Create();<br />byte[] hashData = md5.ComputeHash(Encoding.Default.GetBytes(data));<br />StringBuilder returnValue = new StringBuilder();<br />for (int i = 0; i <><br />{<br />returnValue.Append(hashData[i].ToString());<br />}<br />return returnValue.ToString();<br />}<br /></span><br /><em>the below method will return MD5 hashed string:</em><br /><br /><span style="color:#3333ff;">private string GetSHA1HashData(string data)<br />{<br />SHA1 sha1 = SHA1.Create();<br />byte[] hashData = sha1.ComputeHash(Encoding.Default.GetBytes(data));<br />StringBuilder returnValue = new StringBuilder();<br />for (int i = 0; i <><br />{<br />returnValue.Append(hashData[i].ToString());<br />}<br />return returnValue.ToString();<br />}<br /></span><br />you can save the return value in Database and check it in the another side like SQL Server Membership.<br />that's great, but How can I Validate input Data and stored hashed data in Database?<br /><br /><em>the below method will validate MD5 hashed string:</em><br /><br /><span style="color:#3333ff;">private bool ValidateMD5HashData(string inputData, string storedHashData)<br />{<br />string getHashInputData = GetMD5HashData(inputData);<br />if (string.Compare(getHashInputData, storedHashData) == 0)<br />{<br />return true;<br />}<br />else<br />{<br />return false;<br />}<br />}<br /></span><br /><em>the below method will validate SHA1 hashed string:</em><br /><br /><span style="color:#3333ff;">private bool ValidateSHA1HashData(string inputData, string storedHashData)<br />{<br />string getHashInputData = GetSHA1HashData(inputData);<br />if (string.Compare(getHashInputData, storedHashData) == 0)<br />{<br />return true;<br />}<br />else<br />{<br />return false;<br />}<br />}</span>Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com3tag:blogger.com,1999:blog-7877630238664826501.post-53416526149839394032009-08-12T03:16:00.000-07:002009-08-12T03:56:40.724-07:00How To: Convert Text to Image Using C#I'll show you how to convert any string to image and save it in your hard disk drive.<br />also you can use this sample code to prevent your website content from spiders.<br />there are many benfits.<br /><br />1- Create Windows Forms Application.<br />2- Add Button Control on Form.<br />3- Add TextBox Control on Form and set Multiline to TRUE.<br /><br />Sample Code:<br /><br /><span style="color:#3333ff;">public Color FontColor { get; set; }<br />public Color FontBackColor { get; set; }<br />public string FontName { get; set; }<br />public string ImagePath { get; set; }<br />public int FontSize { get; set; }<br />public int ImageHeight { get; set; }<br />public int ImageWidth { get; set; }<br />public Bitmap ImageText { get; set; }<br />public Graphics ImageGraphics { get; set; }<br />public Font ImageFont { get; set; }<br />public SolidBrush BrushForeColor { get; set; }<br />public SolidBrush BrushBackColor { get; set; }<br />public PointF ImagePointF { get; set; }</span><br /><br /><br /><span style="color:#3333ff;">private void DrawText(string text)<br />{<br />FontColor = Color.Red;<br />FontBackColor = Color.Yellow;<br />FontName = "Arial";<br />FontSize = 10;<br />ImageHeight = textBox1.Height;<br />ImageWidth = textBox1.Width;<br />ImagePath = @"C:\WaleedImageTest.JPEG";<br />ImageText = new Bitmap(ImageWidth, ImageHeight);<br /><br />ImageGraphics = Graphics.FromImage(ImageText);<br /><br />ImageFont = new Font(FontName, FontSize);<br />ImagePointF = new PointF(5, 5);<br />BrushForeColor = new SolidBrush(FontColor);<br />BrushBackColor = new SolidBrush(FontBackColor);<br /><br />ImageGraphics.FillRectangle(BrushBackColor, 0, 0, ImageWidth, ImageHeight);<br />ImageGraphics.DrawString(text, ImageFont, BrushForeColor, ImagePointF);<br /><br />ImageText.Save(ImagePath, ImageFormat.Jpeg);<br />}<br /></span><br /><br /><span style="color:#3333ff;">private void button1_Click(object sender, EventArgs e)<br />{<br />DrawText(textBox1.Text);<br />}</span><br /><br />Then Run Your Application.Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com4tag:blogger.com,1999:blog-7877630238664826501.post-31373590719218917932009-08-11T04:55:00.000-07:002009-08-11T07:46:00.203-07:00How To: Convert Image to String Using C#the easy way to convert any image to string is :<br /><br />1- Convert Image to Memory Stream.<br />2- Convert Memory Stream to Base64String.<br /><br />so in this sample code I will convert the image to string and I'll save this string in text file.<br /><br /><span style="color:#3333ff;">private string ConvertImage(Bitmap sBit)<br />{<br />MemoryStream imageStream = new MemoryStream();<br />sBit.Save(imageStream, ImageFormat.Jpeg);<br /><br />return Convert.ToBase64String(imageStream.ToArray());<br />}<br /></span><br /><span style="color:#3333ff;">private void button1_Click(object sender, EventArgs e)<br />{<br />Bitmap sBit = new Bitmap(@"C:\bmw.jpg");<br />string imageString = ConvertImage(sBit);<br /><br />StreamWriter sw = new StreamWriter(@"C:\waleedelkot.text", false);<br />sw.Write(imageString);<br />sw.Close();<br />}</span>Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com17tag:blogger.com,1999:blog-7877630238664826501.post-26209392188217652682009-08-11T01:51:00.000-07:002009-08-11T02:25:12.853-07:00How To: Create AutoComplete TextBox in Windows Applicationin this article I'll show you how to create AutoComplete TextBox in Windows Application, and I'll Getting the Data from Database.<br /><br />I'll will use MS Access file as a database.<br />so let's start !!<br /><br />1- Create Windows Forms Application.<br />2- add TextBox Control.<br />3- copy the below code into your form.<br /><br /><span style="color:#3333ff;">AutoCompleteStringCollection stringCollection = new AutoCompleteStringCollection();<br /><br />private void AutoCompleteTextBox()<br />{<br />OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\Test.mdb");<br />string con = "select distinct Question from Questions order by Question asc ";<br />OleDbCommand aCommand = new OleDbCommand(con, aConnection);<br /><br />aConnection.Open();<br />OleDbDataReader aReader = aCommand.ExecuteReader();<br /><br />if (aReader.HasRows)<br />{<br />while (aReader.Read())<br />{<br />stringCollection.Add(aReader[0].ToString());<br />}<br />}<br /><br />aReader.Close();<br />aConnection.Close();<br /><br />textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;<br />textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;<br />textBox1.AutoCompleteCustomSource = stringCollection;<br />}<br /><br />private void Form1_Load(object sender, EventArgs e)<br />{<br />AutoCompleteTextBox();<br />}</span>Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com2tag:blogger.com,1999:blog-7877630238664826501.post-60886168106474437922009-08-06T05:15:00.000-07:002009-08-06T05:57:17.616-07:00How To: Add Windows Forms Control in WPFI will describe how we can use windows forms controls in WPF application.<br />I'll assume I have a WPF Application and I want to use DateTimePicker Control, how I can do that in WPF Application?<br /><br />1- Create WPF Application.<br />2- Add Stackpanel control.<br />3- in Solution Explorer Add Reference for:<br /><span style="color:#000066;">* System.Windows.Forms<br />* WindowsFormsIntegration<br /></span><br /><span style="color:#3333ff;">using</span> WindowsControls = System.Windows.Forms;<br /><span style="color:#3333ff;">using</span> WindowsIntegration = System.Windows.Forms.Integration;<br /><br />the below method will Add DateTimePacker Control in WPF:<br /><br /><span style="color:#3333ff;">private void AddDateTimePacker(int x)<br />{<br />for (int i = 0; i < x; i++)<br />{<br />WindowsIntegration.WindowsFormsHost host = new WindowsIntegration.WindowsFormsHost();<br />WindowsControls.DateTimePicker dateTime = new WindowsControls.DateTimePicker();<br /><br />dateTime.Name = "DateTimePicker" + i;<br />dateTime.Left = 0;<br />dateTime.Top = 0;<br />dateTime.Text = string.Empty;<br /><br /><span style="color:#009900;">//add Control To Stack Panel<br /></span>host.Child = dateTime;<br />stackPanel1.Children.Add(host);<br />}<br />}<br /></span>Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com1tag:blogger.com,1999:blog-7877630238664826501.post-22464565735127465412009-08-06T01:52:00.000-07:002009-08-06T04:13:02.646-07:00How To: Get the Value of Textbox Which is Created at Runtime in WPFI will show you how to add Controls at runtime and get their values in WPF.<br /><br />1- Create WPF Application.<br />2- Add Button to add textbox at runtime.<br />3- Add Button to read value from textbox Which is Created at Runtime.<br />4- Add Stackpanel to Host Controls on it.<br /><br />the following method Responsible for Add Controls at runtime:<br /><br /><span style="color:#3333ff;">private void AddTextboxes(int x)<br />{<br />for (int i = 0; i < x; i++)<br />{<br />TextBox txtTest = new TextBox();<br />Thickness txtThickness = new Thickness();<br />txtTest.Name = "Textbox" + i;<br />txtThickness.Left = 0;<br />txtThickness.Top = 0;<br />txtTest.Margin = txtThickness;<br />txtTest.Width = 150;<br />txtTest.Height = 25;<br /><br /><span style="color:#009900;">//add Control to stack panel<br /></span>stackPanel1.Children.Add(txtTest);<br />}<br />}<br /></span><br />the following method Responsible for Read Values:<br /><br /><span style="color:#3333ff;">private void ReadValue()<br />{<br />for (int i = 0; i < stackPanel1.Children.Count; i++)<br />{<br />if (stackPanel1.Children[i] is TextBox)<br />{<br />TextBox txtTest = (TextBox)stackPanel1.Children[i];<br /><br />if (! string.IsNullOrEmpty(txtTest.Text))<br />{<br />MessageBox.Show(txtTest.Text);<br />}<br />}<br />}<br />}</span>Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com0tag:blogger.com,1999:blog-7877630238664826501.post-21719738550330172362009-08-06T00:32:00.000-07:002009-08-06T01:15:12.705-07:00How To: Add Controls at Runtime in WPF<strong>(WPF)</strong>Windows Presentation Foundation:<br /><br />WPF development platform is built on a core programming system, which is extended to support a broad set of application development features, including the application model itself, resources, controls, graphics, layout, data binding, documents, and security.<br /><br />Let's Start our Mission:<br /><br />1- Create New WPF Application.<br />2- add Button from Toolbox.<br />3- add stackPanel from Toolbox.<br /><br />the below Code will add three buttons at Runtime :<br /><br /><span style="color:#3333ff;">private void btnAddControl_Click(object sender, RoutedEventArgs e)<br />{<br /><span style="color:#009900;">//Create three Buttons<br /></span>for (int i = 0; i < 3; i++)<br />{<br />Button btnTest = new Button();<br />Thickness btnThickness = new Thickness();<br />btnTest.Content = "Button" + i;<br />btnTest.Name = "Button" + i;<br />btnThickness.Left = 0;<br />btnThickness.Top = 0;<br />btnTest.Margin = btnThickness;<br />btnTest.Width = 150;<br />btnTest.Height = 25;<br /><br /><span style="color:#009900;">//add Control to stack panel<br /></span>stackPanel1.Children.Add(btnTest);<br />}<br />}</span>Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com3tag:blogger.com,1999:blog-7877630238664826501.post-52780429304101196922009-08-05T03:08:00.000-07:002009-08-05T07:10:29.015-07:00How To: Pass Authentication Between Two ASP.NET Applicationsif you have two Web applications and every application hosted in separated Server<br />also every web Application has Login Page, so how we can save our credentials once we logged on first web application and if I want to go to the second Application without the second application request my authentication again.<br /><br />there are many solutions for this issue:<br />but I will talk about one solution and it is "Cookie Solution"<br />also I will show you how to pass authentications between applications using cookies<br /><br />1- Create two ASP.NET Web Applications (TestOne - TestTwo);<br />2- Create Login Page in Every Application<br />3- Configure web.config File in every application to be support Membership<br />for more information Read<br /><a href="http://waleedelkot.blogspot.com/2009/06/how-to-use-sql-membership-provider-in.html"><span style="color:#3333ff;">How To: Use SQL Membership Provider in ASP.NET</span></a><span style="color:#3333ff;"><br /></span><br />4-in TestOne Application in Login Page put the Following Code in <strong>(Page_Load)</strong> Event:<br /><br /><span style="color:#3333ff;">HttpCookie userName = Request.Cookies.Get("UserName");<br />HttpCookie password = Request.Cookies.Get("Password");<br /><br />if (userName != null password != null)<br />{<br />if (Membership.ValidateUser(userName.Value, password.Value))<br />{<br />FormsAuthentication.RedirectFromLoginPage(userName.Value, false);<br />}<br />}<br /><br /><span style="color:#000000;">5- then Publish TestOne Web Application in your IIS<br />6- in TestTwo Web Application in Defualt Page put the following Coed in<br /><strong>(Page Load)</strong> Event:<br /></span><br />HttpCookie username = new HttpCookie("UserName", "wael");<br />HttpCookie password = new HttpCookie("Password", "1234!@#$");<br />Response.Cookies.Add(username);<br />Response.Cookies.Add(password);<br />Response.Redirect("http://localhost/waleedelkot/Default.aspx");<br /><br /><span style="color:#000000;">then TestTwo Application Will connect to TestOne without request your authentication again.</span><br /></span><span style="color:#3333ff;"></span>Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com2tag:blogger.com,1999:blog-7877630238664826501.post-59166306559785619432009-08-05T01:49:00.000-07:002009-08-05T02:12:05.964-07:00How To: Set Image Source using Java Scriptif you want to set image source from (html Button) at run time follow the following steps.<br /><br />1- Create ASP.NET Web Application.<br />2- in Default Page Create Html Button and html Image.<br />3- Set Image id to "TestImage".<br /><br />copy the following java script function into your default page Source<br /><br /><span style="color:#3333ff;">function SetImage()<br />{<br />document.getElementById('TestImage').setAttribute('src', 'Images/Water lilies.jpg');<br />}<br /></span><br />4- in html Button call SetImage Method<br /><br /><span style="color:#3333ff;">onclick="SetImage1()"</span>Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com0tag:blogger.com,1999:blog-7877630238664826501.post-84980944651645610192009-08-05T01:13:00.000-07:002009-08-05T01:44:47.646-07:00How To: Generate Barcode in ASP.NETin this Article I'll Describe How To Generate Barcode Image in ASP.NET Without Using third party.<br /><br />first thing barcode depending on Fonts and there are many fonts used for barcode<br />also there are many free fonts you can download it.<br /><br />I'll Will Use <strong>Code 39 Font</strong>, You can download it from:<br /><span style="color:#3333ff;"><a href="http://www.barcodesinc.com/free-barcode-font/">http://www.barcodesinc.com/free-barcode-font/</a></span><br /><br />Copy Font to <strong>Windows\Fonts</strong> Folder<br /><br />Steps:<br /><br />1- Create ASP.NET Web Application.<br />2- in The Main Web Application Root Create Folder "Images".<br />3- in The Default Page Create Button "btnBarcode"<br />4- Copy the Following Code into your page:<br /><br /><span style="color:#3333ff;">public string ProductCode { get; set; }<br />public string ProductName { get; set; }<br />public string ProductPrice { get; set; }<br /><br />Font arial = new Font("Arial", 8, FontStyle.Regular, GraphicsUnit.Point);<br />public Font Arial<br />{<br />get { return arial; }<br />}<br /><br />Font threeOfNine = new Font("Free 3 of 9", 15, FontStyle.Regular, GraphicsUnit.Point);<br />public Font ThreeOfNine<br />{<br />get { return threeOfNine; }<br />}<br /><br />Bitmap barcodeImage = new Bitmap(85, 55);<br />public Bitmap BarCodeImage<br />{<br />get { return barcodeImage; }<br />} </span><br /><br /><span style="color:#3333ff;">private void GenerateBarcode()<br />{<br />Graphics graphics = Graphics.FromImage(BarCodeImage);<br />SizeF dataSize = graphics.MeasureString(ProductCode, ThreeOfNine);<br /><br /><span style="color:#009900;">//Refresh our Graphics object with the new bitmap<br /></span>graphics = Graphics.FromImage(BarCodeImage);<br /><br />graphics.Clear(Color.White);<br />graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;<br /><br />graphics.DrawString(ProductCode, ThreeOfNine, new SolidBrush(Color.Black), 0, 15);<br />graphics.DrawString(ProductName, Arial, new SolidBrush(Color.Black), 0, 0);<br />graphics.DrawString(ProductCode, arial, new SolidBrush(Color.Black), 10, 30);<br />graphics.DrawString("Price " + ProductPrice + " L.E", Arial, new SolidBrush(Color.Black), 0, 40);<br /><br /><span style="color:#009900;">//force the Graphics object to execute any pending operations.</span><br />graphics.Flush();<br /><br /><span style="color:#009900;">//Dispose our objects<br /></span>threeOfNine.Dispose();<br />graphics.Dispose();<br />}</span><br /><br /><span style="color:#3333ff;">protected void btnBarcode_Click(object sender, EventArgs e)<br />{<br />ProductCode = "ABCD-12345";<br />ProductName = "Congestal";<br />ProductPrice = "20000";<br /><br />GenerateBarcode();<br />BarCodeImage.Save(Server.MapPath("~/Images/barcode.gif"), ImageFormat.Gif);<br />Response.WriteFile(Server.MapPath("~/Images/barcode.gif"));<br />}</span>Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com0tag:blogger.com,1999:blog-7877630238664826501.post-49670259591649755842009-06-26T06:04:00.000-07:002009-06-26T07:06:28.811-07:00Office 2007 OCR Sample Code Using C#<strong>this sample code for:</strong><br /><br />1- scan image Format in Specify Directory.<br />2- read text from these images.<br />3- save text from each image in text fle automaticly.<br />4- handle problems with images<br /><br /><strong>Sample Code:</strong><br /><br /><span style="color:#000099;">public void CheckFileType(string directoryPath) </span><br /><span style="color:#000099;"> { </span><br /><span style="color:#000099;"> IEnumerator files = Directory.GetFiles(directoryPath).GetEnumerator(); </span><br /><span style="color:#000099;"> while (files.MoveNext()) </span><br /><span style="color:#000099;"> { </span><br /><span style="color:#000099;"><span style="color:#006600;"> //get file extension</span> </span><br /><span style="color:#000099;"> string fileExtension = Path.GetExtension(Convert.ToString(files.Current));</span><br /><span style="color:#000099;"><br /><span style="color:#006600;"> //get file name without extenstion</span> </span><br /><span style="color:#000099;"> string fileName=Convert.ToString(files.Current).Replace(fileExtension,string.Empty);</span><br /><span style="color:#000099;"><br /><span style="color:#006600;"> //Check for JPG File Format</span> </span><br /><span style="color:#000099;"> if (fileExtension == ".jpg") </span><br /><span style="color:#000099;"> { </span><br /><span style="color:#000099;"> try </span><br /><span style="color:#000099;"> { </span><br /><span style="color:#000099;"><span style="color:#006600;"> //OCR Operations ...</span> </span><br /><span style="color:#000099;"> MODI.Document md = new MODI.Document(); </span><br /><span style="color:#000099;"> md.Create(Convert.ToString(files.Current)); </span><br /><span style="color:#000099;"> md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true); </span><br /><span style="color:#000099;"> MODI.Image image = (MODI.Image)md.Images[0];</span><br /><span style="color:#000099;"><br /> <span style="color:#006600;">//create text file with the same Image file name</span> </span><br /><span style="color:#000099;"> FileStream createFile = new FileStream(fileName + ".txt",FileMode.CreateNew);</span><br /><span style="color:#000099;"><br /><span style="color:#006600;"> //save the image text in the text file</span> </span><br /><span style="color:#000099;"> StreamWriter writeFile = new StreamWriter(createFile); </span><br /><span style="color:#000099;"> writeFile.Write(image.Layout.Text); </span><br /><span style="color:#000099;"> writeFile.Close(); </span><br /><span style="color:#000099;"> } </span><br /><span style="color:#000099;"> catch (Exception) </span><br /><span style="color:#000099;"> { </span><br /><span style="color:#000099;"><span style="color:#006600;"> //MessageBox.Show("This Image hasn't a text or has a problem", </span></span><br /><span style="color:#000099;"><span style="color:#006600;"> "OCR Notifications", </span></span><br /><span style="color:#000099;"><span style="color:#006600;"> MessageBoxButtons.OK, MessageBoxIcon.Information); </span> </span><br /><span style="color:#000099;"> } </span><br /><span style="color:#000099;"> } </span><br /><span style="color:#000099;"> } </span><br /><span style="color:#000099;"> }</span>Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com8tag:blogger.com,1999:blog-7877630238664826501.post-27048187753856823872009-06-23T14:45:00.000-07:002009-06-23T14:48:00.521-07:00How To: Create Thumbnail Images in ASP.NET<div style="margin: 0in 0in 12pt"><span style="font-size: 12pt; color: black; line-height: 115%">A thumbnail image is a small version of an image. You can create a thumbnail image by the following Methods:</span></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt; color: blue">We will Use: </span><span style="font-size: 12pt">System.Drawing.Imaging</span></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"> </div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><b><u><span style="font-size: 12pt">Copy the Following Code into your Class:</span></u></b></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"> </div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt; color: blue">public</span><span style="font-size: 12pt"> <span style="color: blue">void</span> GenerateThumbnail(<span style="color: blue">string</span> thumbPath, <span style="color: blue">int</span> thumbWidth, <span style="color: blue">int</span> thumbHeight, <span style="color: blue">string</span> thumbNewPath)</span></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt"> {</span></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt"> <span style="color: #2b91af">String</span> imageName = <span style="color: #2b91af">Path</span>.GetFileName(thumbPath);</span></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"> </div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt"> <span style="color: blue">int</span> imageHeight = thumbHeight;</span></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt"> <span style="color: blue">int</span> imageWidth = thumbWidth;</span></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"> </div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt"> <span style="color: #2b91af">Image</span> fullSizeImg = <span style="color: #2b91af">Image</span>.FromFile(thumbPath);</span></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt"> <span style="color: #2b91af">Image</span>.<span style="color: #2b91af">GetThumbnailImageAbort</span> dummyCallBack = <span style="color: blue">new</span> <span style="color: #2b91af">Image</span>.<span style="color: #2b91af">GetThumbnailImageAbort</span>(ThumbnailCallback);</span></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt"> <span style="color: #2b91af">Image</span> thumbNailImage = fullSizeImg.GetThumbnailImage(imageWidth, imageHeight, dummyCallBack, <span style="color: #2b91af">IntPtr</span>.Zero);</span></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"> </div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt"> thumbNailImage.Save(thumbNewPath, <span style="color: #2b91af">ImageFormat</span>.Jpeg);</span></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt"> thumbNailImage.Dispose();</span></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt"> fullSizeImg.Dispose();</span></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"> </div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt"> }</span></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"> </div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt"> <span style="color: blue">public</span> <span style="color: blue">bool</span> ThumbnailCallback()</span></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt"> {</span></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt"> <span style="color: blue">return</span> <span style="color: blue">false</span>;</span></div><br /><div style="border-right: medium none; padding-right: 0in; border-top: medium none; padding-left: 0in; padding-bottom: 1pt; border-left: medium none; padding-top: 0in; border-bottom: windowtext 1pt solid"><br /><div style="border-right: medium none; padding-right: 0in; border-top: medium none; padding-left: 0in; padding-bottom: 0in; margin: 0in 0in 12pt; border-left: medium none; padding-top: 0in; border-bottom: medium none"><span style="font-size: 12pt; line-height: 115%"> }</span></div><br /><div style="border-right: medium none; padding-right: 0in; border-top: medium none; padding-left: 0in; padding-bottom: 0in; margin: 0in 0in 12pt; border-left: medium none; padding-top: 0in; border-bottom: medium none"><span style="font-size: 12pt; line-height: 115%">I think the following Code is better or I can say it’s a good sample for optimizing the above code.</span></div><br /></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt; color: blue">public</span><span style="font-size: 12pt"> <span style="color: blue">void</span> GenerateThumbnail (<span style="color: blue">string</span> thumbPath, <span style="color: blue">int</span> thumbWidth, <span style="color: blue">int</span> thumbHeight, <span style="color: blue">string</span> thumbNewPath)</span></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt"> {</span></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt"> <span style="color: #2b91af">Image</span> image = <span style="color: blue">new</span> <span style="color: #2b91af">Bitmap</span>(thumbPath);</span></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt"> <span style="color: #2b91af">Image</span> imageThumbnail = image.GetThumbnailImage(thumbWidth, thumbHeight, <span style="color: blue">null</span>, <span style="color: blue">new</span> <span style="color: #2b91af">IntPtr</span>());</span></div><br /><div style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 12pt"> imageThumbnail.Save(thumbNewPath);</span></div><br /><div style="border-right: medium none; padding-right: 0in; border-top: medium none; padding-left: 0in; padding-bottom: 1pt; border-left: medium none; padding-top: 0in; border-bottom: windowtext 1pt solid"><br /><div style="border-right: medium none; padding-right: 0in; border-top: medium none; padding-left: 0in; padding-bottom: 0in; margin: 0in 0in 12pt; border-left: medium none; padding-top: 0in; border-bottom: medium none"><span style="font-size: 12pt; line-height: 115%"> }</span></div><br /></div>Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com0tag:blogger.com,1999:blog-7877630238664826501.post-38583134344559751892009-06-23T14:43:00.000-07:002009-06-23T14:44:57.025-07:00How To: Use Active Directory Membership Provider in ASP.NET<div style="MARGIN: 0in 0in 12pt"><span style="LINE-HEIGHT: 115%;font-size:12;color:black;" >The ASP.NET version 2.0 membership feature provides secure credential storage for application users. </span></div><br /><div style="MARGIN: 0in 0in 12pt"><span style="LINE-HEIGHT: 115%;font-size:12;color:black;" >We Will Use The Following:</span></div><br /><div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"><span style="LINE-HEIGHT: 115%;font-size:12;color:black;" >-<span style="FONT: 7pt 'Times New Roman'"> </span></span><span style="LINE-HEIGHT: 115%;font-size:12;color:black;" >Web Page Named Login.aspx and another Web Page Named CreateUser.aspx</span></div><br /><div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"><span style="LINE-HEIGHT: 115%;font-size:12;color:black;" >-<span style="FONT: 7pt 'Times New Roman'"> </span></span><span style="LINE-HEIGHT: 115%;font-size:12;color:black;" >Login Control</span></div><br /><div style="MARGIN: 0in 0in 12pt 0.5in; TEXT-INDENT: -0.25in"><span style="LINE-HEIGHT: 115%;font-size:12;color:black;" >-<span style="FONT: 7pt 'Times New Roman'"> </span></span><span style="LINE-HEIGHT: 115%;font-size:12;color:black;" >Create User Wizard Control </span></div><br /><div style="MARGIN: 0in 0in 12pt"><b><span style="LINE-HEIGHT: 115%;font-size:12;color:black;" >Steps:</span></b></div><br /><div style="MARGIN: auto 0in; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"><b><span style="font-size:130%;"><span style="LINE-HEIGHT: 140%;font-size:12;color:black;" >1- Configure Forms Authentication</span><span style="LINE-HEIGHT: 140%;font-size:9;color:black;" >in Web.config File<br /><br /></span></span></b></div><br /><div style="VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"><span style="LINE-HEIGHT: 140%;font-size:12;color:black;" >To configure forms authentication, set the <<strong>authentication</strong>> element's <strong>mode</strong> attribute to <strong>"Forms" </strong>and then configure your application's Web.config file as shown in the following example.<br /><br /><br /><br /></span></div><br /><divre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"></divre><br /><span style="color:#0000ff;"><span style="font-size:85%;"><authentication mode="Forms"></span></span><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> <forms loginUrl="Login.aspx" </span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> protection="All" </span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> timeout="30" </span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> name="AppNameCookie" </span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> path="/FormsAuth" </span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> requireSSL="false" </span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> slidingExpiration="true" </span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> defaultUrl="default.aspx"</span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> cookieless="UseCookies"</span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> enableCrossAppRedirects="false"/></span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"></authentication></span></span><br /><br /><span style="LINE-HEIGHT: 140%;font-size:12;color:black;" >Where: </span></pre><br /><ul type="disc"><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><strong><span style="LINE-HEIGHT: 140%;font-size:12;" >loginUrl</span></strong><span style="LINE-HEIGHT: 140%;font-size:12;" > points to the login page. You should place this in a folder that requires Secure Sockets Layer (SSL) for access. </span></li><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><strong><span style="LINE-HEIGHT: 140%;font-size:12;" >protection</span></strong><span style="LINE-HEIGHT: 140%;font-size:12;" > is set to <strong>"All"</strong> to specify privacy and integrity for the forms authentication ticket. </span></li><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><strong><span style="LINE-HEIGHT: 140%;font-size:12;" >timeout</span></strong><span style="LINE-HEIGHT: 140%;font-size:12;" > is used to specify a limited session lifetime. </span></li><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><strong><span style="LINE-HEIGHT: 140%;font-size:12;" >name</span></strong><span style="LINE-HEIGHT: 140%;font-size:12;" > and <strong>path</strong> are set to unique values for the current application. </span></li><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><strong><span style="LINE-HEIGHT: 140%;font-size:12;" >requireSSL</span></strong><span style="LINE-HEIGHT: 140%;font-size:12;" > is set to <strong>"false"</strong>. This configuration means that authentication cookie can be transmitted over channels that are not SSL-protected. If you are concerned about session hijacking, you should consider setting this to <strong>"true"</strong>. </span></li><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><strong><span style="LINE-HEIGHT: 140%;font-size:12;" >slidingExpiration</span></strong><span style="LINE-HEIGHT: 140%;font-size:12;" > is set to <strong>"true"</strong> to enforce a sliding session lifetime. This means that the <strong>timeout</strong> is reset after each request to your application. </span></li><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><strong><span style="LINE-HEIGHT: 140%;font-size:12;" >defaultUrl</span></strong><span style="LINE-HEIGHT: 140%;font-size:12;" > is set to the Default.aspx page for the application. </span></li><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><strong><span style="LINE-HEIGHT: 140%;font-size:12;" >cookieless</span></strong><span style="LINE-HEIGHT: 140%;font-size:12;" > is set to <strong>"UseCookies"</strong> to specify that the application uses cookies to send the authentication ticket to the client. </span></li><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><strong><span style="LINE-HEIGHT: 140%;font-size:12;" >enableCrossAppRedirects</span></strong><span style="LINE-HEIGHT: 140%;font-size:12;" > is set to <strong>"false"</strong> to indicate that the application cannot redirect requests outside the application scope. </span></li><br /></ul><br /><div style="VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"><span style="LINE-HEIGHT: 140%;font-size:12;color:black;" >Add the following <<strong>authorization</strong>> element after the <<strong>authentication</strong>> element. This permits only authenticated users to access the application. The previously established <strong>loginUrl</strong> attribute of the <<strong>authentication</strong>> element will redirect unauthenticated requests to the Login.aspx page.<br /><br /><br /><br /></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" ><authorization> </span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > <deny users="?" /></span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > <allow users="*" /></span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" ></authorization></span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"> </div><br /><div style="MARGIN: 0in 0in 12pt"><b><span style="LINE-HEIGHT: 115%;font-size:9;color:black;" >Configure the ActiveDirectoryMembershipProvider in Web.config File</span></b></div><br /><div style="MARGIN: 0in 0in 12pt"><span style="LINE-HEIGHT: 115%;font-size:12;color:black;" >Configure the <strong>ActiveDirectoryMembershipProvider</strong> in your application's Web.config file as shown in the following example.</span></div><br /><div style="MARGIN: 0in 0in 12pt"><span style="LINE-HEIGHT: 115%;font-size:12;color:black;" >There is An Important Point in this Case How I Can Get My Active Directory Connection String</span></div><br /><div style="MARGIN: 0in 0in 12pt"><span style="LINE-HEIGHT: 115%;font-size:12;color:black;" >Please Visit:</span></div><br /><div style="MARGIN: 0in 0in 12pt"><span style="LINE-HEIGHT: 115%;font-size:8;color:black;" ><a href="http://waleedelkot.blogspot.com/2009/01/get-active-directory-connection-string.html">http://waleedelkot.blogspot.com/2009/01/get-active-directory-connection-string.html</a></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" ><connectionStrings></span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > <add name="ADConnectionString" </span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > connectionString=</span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > "LDAP://domain.testing.com/CN=Users,DC=domain,DC=testing,DC=com" /></span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" ></connectionStrings></span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"></span> </div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" ><system.web></span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > ...</span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > <membership defaultProvider="MembershipADProvider"></span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > <providers></span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > <add name="MembershipADProvider"</span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > type="System.Web.Security.ActiveDirectoryMembershipProvider,System.Web,</span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"</span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > connectionStringName="ADConnectionString" </span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > connectionUsername="<domainName>\administrator" </span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > connectionPassword="password"/></span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > </providers></span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > </membership></span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > ...</span></span></div><br /><div style="MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" ></system.web></span></span></div><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:black;"><span style="font-size:85%;">The Last Step:</span></span></pre><br /><pre style="MARGIN-LEFT: 0.5in; VERTICAL-ALIGN: top; WORD-BREAK: break-all; TEXT-INDENT: -0.25in; LINE-HEIGHT: 140%"><span style="color:black;"><span style="font-size:85%;">-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span><span style="color:black;"><span style="font-size:85%;">Drag and drop Login Control into the Login page.</span></span></pre><br /><pre style="MARGIN-LEFT: 0.5in; VERTICAL-ALIGN: top; WORD-BREAK: break-all; TEXT-INDENT: -0.25in; LINE-HEIGHT: 140%"><span style="color:black;"><span style="font-size:85%;">-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span><span style="color:black;"><span style="font-size:85%;">Drag and drop Create User Wizard Control into the CreateUser page.</span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:black;"><span style="font-size:85%;">Now Your Web Application or your Website Secured.</span></span></pre>Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com0tag:blogger.com,1999:blog-7877630238664826501.post-43001373716729292362009-06-23T14:37:00.000-07:002009-06-23T14:41:59.510-07:00How To: Use SQL Membership Provider in ASP.NET<div style="MARGIN: 0in 0in 12pt"><span style="LINE-HEIGHT: 115%;font-size:12;color:black;" >The ASP.NET version 2.0 membership feature provides secure credential storage for application users. </span></div><br /><div style="MARGIN: 0in 0in 12pt"><span style="LINE-HEIGHT: 115%;font-size:12;color:black;" >We Will Use The Following:</span></div><br /><div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"><span style="LINE-HEIGHT: 115%;font-size:12;color:black;" >-<span style="FONT: 7pt 'Times New Roman'"> </span></span><span style="LINE-HEIGHT: 115%;font-size:12;color:black;" >Web Page Named Login.aspx and another Web Page Named CreateUser.aspx</span></div><br /><div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"><span style="LINE-HEIGHT: 115%;font-size:12;color:black;" >-<span style="FONT: 7pt 'Times New Roman'"> </span></span><span style="LINE-HEIGHT: 115%;font-size:12;color:black;" >Login Control</span></div><br /><div style="MARGIN: 0in 0in 12pt 0.5in; TEXT-INDENT: -0.25in"><span style="LINE-HEIGHT: 115%;font-size:12;color:black;" >-<span style="FONT: 7pt 'Times New Roman'"> </span></span><span style="LINE-HEIGHT: 115%;font-size:12;color:black;" >Create User Wizard Control </span></div><br /><div style="MARGIN: 0in 0in 12pt"><b><span style="LINE-HEIGHT: 115%;font-size:8;color:black;" >Steps:</span></b></div><br /><div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"><b><span style="LINE-HEIGHT: 115%;font-size:9;color:black;" >1-<span style="FONT: 7pt 'Times New Roman'"> </span></span></b><b><span style="LINE-HEIGHT: 115%;font-size:9;color:black;" >Configure Forms Authentication in Web.config File</span></b></div><br /><div style="MARGIN: 0in 0in 12pt 0.5in"><b></b> </div><br /><div style="VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"><span style="LINE-HEIGHT: 140%;font-size:12;color:black;" >To configure forms authentication, set the <<strong>authentication</strong>> element's <strong>mode</strong> attribute to <strong>"Forms" </strong>and then configure your application's Web.config file as shown in the following example.<br /><br /><br /><br /></span></div><br /><div style="MARGIN: 0in 0in 0pt 0.5in; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" ><authentication mode="Forms"></span></span></div><br /><div style="MARGIN: 0in 0in 0pt 0.5in; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > <forms loginUrl="Login.aspx" </span></span></div><br /><div style="MARGIN: 0in 0in 0pt 0.25in; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > protection="All" </span></span></div><br /><div style="MARGIN: 0in 0in 0pt 0.25in; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > timeout="30" </span></span></div><br /><div style="MARGIN: 0in 0in 0pt 0.5in; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > name="AppNameCookie" </span></span></div><br /><div style="MARGIN: 0in 0in 0pt 0.5in; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > path="/FormsAuth" </span></span></div><br /><div style="MARGIN: 0in 0in 0pt 0.5in; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > requireSSL="false" </span></span></div><br /><div style="MARGIN: 0in 0in 0pt 0.5in; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > slidingExpiration="true" </span></span></div><br /><div style="MARGIN: 0in 0in 0pt 0.5in; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > defaultUrl="default.aspx"</span></span></div><br /><div style="MARGIN: 0in 0in 0pt 0.5in; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > cookieless="UseCookies"</span></span></div><br /><div style="MARGIN: 0in 0in 0pt 0.5in; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" > enableCrossAppRedirects="false" /></span></span></div><br /><div style="MARGIN: 0in 0in 0pt 0.5in; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" ></authentication></span></span></div><br /><ul type="disc"><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><strong><span style="LINE-HEIGHT: 140%;font-size:12;" >loginUrl</span></strong><span style="LINE-HEIGHT: 140%;font-size:12;" > points to the login page. You should place this in a folder that requires Secure Sockets Layer (SSL) for access. </span></li><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><strong><span style="LINE-HEIGHT: 140%;font-size:12;" >protection</span></strong><span style="LINE-HEIGHT: 140%;font-size:12;" > is set to <strong>"All"</strong> to specify privacy and integrity for the forms authentication ticket. </span></li><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><strong><span style="LINE-HEIGHT: 140%;font-size:12;" >timeout</span></strong><span style="LINE-HEIGHT: 140%;font-size:12;" > is used to specify a limited session lifetime. </span></li><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><strong><span style="LINE-HEIGHT: 140%;font-size:12;" >name</span></strong><span style="LINE-HEIGHT: 140%;font-size:12;" > and <strong>path</strong> are set to unique values for the current application. </span></li><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><strong><span style="LINE-HEIGHT: 140%;font-size:12;" >requireSSL</span></strong><span style="LINE-HEIGHT: 140%;font-size:12;" > is set to <strong>"false"</strong>. This configuration means that authentication cookie can be transmitted over channels that are not SSL-protected. If you are concerned with session hijacking, you should consider setting this to <strong>"true"</strong>. </span></li><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><strong><span style="LINE-HEIGHT: 140%;font-size:12;" >slidingExpiration</span></strong><span style="LINE-HEIGHT: 140%;font-size:12;" > is set to <strong>"true"</strong> to enforce a sliding session lifetime. This means that the <strong>timeout</strong> is reset after each request to your application. </span></li><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><strong><span style="LINE-HEIGHT: 140%;font-size:12;" >defaultUrl</span></strong><span style="LINE-HEIGHT: 140%;font-size:12;" > is set to the Default.aspx page for the application. </span></li><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><strong><span style="LINE-HEIGHT: 140%;font-size:12;" >cookieless</span></strong><span style="LINE-HEIGHT: 140%;font-size:12;" > is set to <strong>"UseCookies"</strong> to specify that the application uses cookies to send the authentication ticket to the client. </span></li><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><strong><span style="LINE-HEIGHT: 140%;font-size:12;" >enableCrossAppRedirects</span></strong><span style="LINE-HEIGHT: 140%;font-size:12;" > is set to <strong>"false"</strong>, to indicate that the application cannot redirect the request outside the application scope. </span></li><br /></ul><br /><div style="MARGIN: 0in 0in 2.25pt 0.5in; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"> </div><br /><div style="VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"><span style="LINE-HEIGHT: 140%;font-size:12;color:black;" >Add the following <<strong>authorization</strong>> element after the <<strong>authentication</strong>> element. This permits only authenticated users to access the application. The previously established <strong>loginUrl</strong> attribute of the <<strong>authentication</strong>> element redirects unauthenticated requests to the Login.aspx page</span><br /><br /> </div><br /><divre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"></divre><br /><span style="color:#0000ff;"><span style="font-size:85%;"><authorization> </span></span><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> <deny users="?" /></span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> <allow users="*" /></span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> </authorization><br /></span></span><br /><b><span style="LINE-HEIGHT: 140%;font-size:9;color:black;" >2-<span style="FONT: 7pt 'Times New Roman'"> </span></span></b><b><span style="LINE-HEIGHT: 140%;font-size:9;color:black;" >Install the Membership Database</span></b></pre><br /><div style="MARGIN: 0in 0in 7.5pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"><span style="LINE-HEIGHT: 140%;font-size:12;color:black;" >Before you can use the <b>SqlMembershipProvider</b>, you must install the SQL Server membership database.</span></div><br /><div style="MARGIN: 0in 0in 7.5pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"><span style="LINE-HEIGHT: 140%;font-size:12;color:black;" >To install the membership database, log on to your server with an account that has authority to administrate SQL Server (such as the Administrator account). Open the Visual Studio 2005 command prompt (Start > Microsoft Visual Studio 2005 or 2008 > Visual Studio Tools > Visual Studio 2005 command prompt), and run the following command:</span></div><br /><div style="MARGIN: 0in 0in 7.5pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="LINE-HEIGHT: 140%;font-size:12;" >aspnet_regsql.exe -E -S localhost -A m</span></span></div><br /><div style="MARGIN: 0in 0in 7.5pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"><span style="LINE-HEIGHT: 140%;font-size:12;color:black;" >Where: </span></div><br /><ul type="disc"><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><b><span style="LINE-HEIGHT: 140%;font-size:12;" >-E</span></b><span style="LINE-HEIGHT: 140%;font-size:12;" > indicates authenticate using the Windows credentials of the currently logged on user. </span></li><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><b><span style="LINE-HEIGHT: 140%;font-size:12;" >-S</span></b><span style="LINE-HEIGHT: 140%;font-size:12;" > (server) indicates the name of the server where the database will be installed or is already installed. </span></li><br /><li style="MARGIN: 0in 0in 2.25pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%color:black;" ><b><span style="LINE-HEIGHT: 140%;font-size:12;" >-A m</span></b><span style="LINE-HEIGHT: 140%;font-size:12;" > indicates add membership support. This creates the tables and stored procedures required by the membership provider. </span></li><br /></ul><br /><div style="MARGIN: 0in 0in 5pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"><b><span style="LINE-HEIGHT: 140%;font-size:8;color:black;" >In Web.config</span></b></div><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"><connectionStrings></span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> <add name="MySqlConnection" connectionString="Data Source=MySqlServer;Initial Catalog=aspnetdb;Integrated Security=SSPI;" /></span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"></connectionStrings></span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"><system.web></span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;">...</span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:black;"><span style="font-size:85%;"> </span><span style="color:#0000ff;"><span style="font-size:85%;"><membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15"></span></span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> <providers></span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> <clear /></span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> <add </span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> name="SqlProvider" </span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> type="System.Web.Security.SqlMembershipProvider" </span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> connectionStringName="MySqlConnection"</span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> applicationName="MyApplication"</span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> enablePasswordRetrieval="false"</span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> enablePasswordReset="true"</span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> requiresQuestionAndAnswer="true"</span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> requiresUniqueEmail="true"</span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> passwordFormat="Hashed" /></span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> </providers></span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:#0000ff;"><span style="font-size:85%;"> </membership></span></span></pre><br /><pre style="VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: 140%"><span style="color:black;"><span style="font-size:85%;">The Last Step:</span></span></pre><br /><pre style="MARGIN-LEFT: 0.5in; VERTICAL-ALIGN: top; WORD-BREAK: break-all; TEXT-INDENT: -0.25in; LINE-HEIGHT: 140%"><span style="color:black;"><span style="font-size:85%;">-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span><span style="color:black;"><span style="font-size:85%;">Drag and drop Login Control into the Login page</span></span></pre><br /><pre style="MARGIN-LEFT: 0.5in; VERTICAL-ALIGN: top; WORD-BREAK: break-all; TEXT-INDENT: -0.25in; LINE-HEIGHT: 140%"><span style="color:black;"><span style="font-size:85%;">-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span><span style="color:black;"><span style="font-size:85%;">Drag and drop Create User Wizard Control into the CreateUser page</span></span></pre><br /><span style="LINE-HEIGHT: 115%;font-size:11;color:black;" >Now Your Web Application or your Website Secured.</span>Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com0tag:blogger.com,1999:blog-7877630238664826501.post-60405363733797176252009-06-06T04:57:00.000-07:002009-06-07T02:14:44.226-07:00How To: Format DateTime in SQL Server<p>I'll Show You How To Format DataTime in SQL SERVER.</p><p><br />When expression is a date or time data type, style can be one of the values shown in the below Text:</p><ul><li>101 >>>>>>>> mm/dd/yy</li><li>102 >>>>>>>> yy.mm.dd</li><li>103 >>>>>>>> dd/mm/yy</li><li>104 >>>>>>>> dd.mm.yy</li><li>111 >>>>>>>> yy/mm/dd</li><li>114 >>>>>>>> hh:mi:ss:mmm(24h)</li></ul><p><a href="http://msdn.microsoft.com/en-us/library/aa226054(SQL.80).aspx"><span style="color:#3333ff;">more formats</span></a></p><p>we will assume we have a table contain a DateTime data type field, the Result of the below query will be like:</p><p>ex. <strong><span style="color:#3333ff;">SELECT BirthDate FROM MyTable</span></strong></p><p><span style="color:#333333;">the Result will be ("<strong>2/2/1982 1:00:00 AM</strong>")</span></p><p><span style="color:#333333;">so we can use use <strong>Convert Function</strong> To Format DateTime</span></p><p>ex.<span style="color:#3333ff;"> <strong>SELECT CONVERT(CHAR(11),GETDATE(),101) BirthDate FROM MyTable</strong></span></p><p><strong><span style="color:#3333ff;">{Result === 06/07/2009 }</span></strong></p><p><span style="color:#3333ff;"><span style="color:#333333;">ex.</span><strong> SELECT CONVERT(CHAR(11),GETDATE(),114) BirthDate FROM MyTable</strong></span></p><p><strong><span style="color:#3333ff;">{Result === 1:00:00 }</span></strong></p>Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com0tag:blogger.com,1999:blog-7877630238664826501.post-27861368500621477032009-05-31T04:15:00.000-07:002009-06-01T03:47:49.991-07:00How To: Enable Allow Paging in Repeater Using C#<strong>1- I'll Show You how to make a repeater that allow paging.</strong><br /><strong>2- I'll Make a web user control and anyone Can use it in his project.</strong><br /><br /><strong><em>Steps:</em></strong><br /><strong></strong><br /><strong>1- Create A web user control using C# and rename it to RepeaterPager.</strong><br /><strong></strong><br /><strong>2- add four Buttons and one label:</strong><br /><span style="color:#330099;"><strong>Control</strong></span> <span style="color:#330099;"><strong>Name</strong></span> <span style="color:#330099;"><strong>Text</strong></span><br /><br />Button btnNext ><br />Button btnPrevious <<br />Button btnLastRecord >><br />Button btnFirstRecord <<<br /><br /><strong>3- Create property for Object Data Source:</strong><br /><span style="color:#3333ff;">public ObjectDataSource Ods { get; set; }<br /></span><br /><strong>4- Create Property for Repeater Control Or DataList As you like:</strong><br /><span style="color:#3333ff;">public Repeater Rep { get; set; }</span><br /><br /><strong>5- Create Property Get Current Page:</strong><br /><br /><span style="color:#3333ff;">public int CurrentPage<br />{<br />get<br />{<br />object obj = this.ViewState["_CurrentPage"];<br />if (obj == null)<br />{<br />return 0;<br />}<br />else<br />{<br />return (int)obj;<br />}<br />}<br />set<br />{<br />this.ViewState["_CurrentPage"] = value;<br />}<br />}</span><br /><br /><strong>6- Bind Data in Repeater Control and Return number of Pages:</strong><br /><br /><br /><span style="color:#3333ff;">public int ItemsGet()<br />{<br />PagedDataSource objPds = new PagedDataSource();<br />objPds.DataSource = Ods.Select();<br />int x = objPds.Count;<br />objPds.AllowPaging = true;<br />objPds.PageSize = 1;<br />objPds.CurrentPageIndex = CurrentPage;<br />if (objPds.Count > 0)<br />{<br />btnPrevious.Visible = true;<br />btnNext.Visible = true;<br />btnLastRecord.Visible = true;<br />btnFirstRecord.Visible = true;<br />lblCurrentPage.Visible = true;<br />lblCurrentPage.Text = "Page: " + Convert.ToString(CurrentPage + 1) + " of " + Convert.ToString(objPds.PageCount);<br />}<br />else<br />{<br />btnPrevious.Visible = false;<br />btnNext.Visible = false;<br />btnLastRecord.Visible = false;<br />btnFirstRecord.Visible = false;<br />lblCurrentPage.Visible = false;<br />}<br />btnPrevious.Enabled = !objPds.IsFirstPage;<br />btnNext.Enabled = !objPds.IsLastPage;<br />btnLastRecord.Enabled = !objPds.IsLastPage;<br />btnFirstRecord.Enabled = !objPds.IsFirstPage;<br />Rep.DataSource = objPds;<br />Rep.DataBind();<br />return x;<br />}</span><br /><br /><strong>7- Buttons Controls Code:</strong><br /><br /><span style="color:#3333ff;">protected void btnPrevious_Click(object sender, EventArgs e)<br />{<br />CurrentPage -= 1;<br />ItemsGet();<br />}<br />protected void btnNext_Click(object sender, EventArgs e)<br />{<br />CurrentPage += 1;<br />ItemsGet();<br />}<br />protected void btnLastRecord_Click(object sender, EventArgs e)<br />{<br />CurrentPage = ItemsGet() -1;<br />ItemsGet();<br />}<br />protected void btnFirstRecord_Click(object sender, EventArgs e)<br />{<br />CurrentPage = 0;<br />ItemsGet();<br />}</span><br /><strong>8- in (Web User Control) Load Event call GetItems Property:</strong><br /><br /><span style="color:#3333ff;">protected void Page_Load(object sender, EventArgs e)<br />{<br />ItemsGet();<br />}</span><br /><span style="color:#3333ff;"><br /></span><strong>How To Use this Control:</strong><br /><strong>1- Create ASP.Net Page</strong><br /></span><strong>2- Add Repeater1 and ObjectDataSource1 to your page </strong><br /><strong>3- in Page_load Event Put the following code:<br /></strong><span style="color:#3333ff;">protected void Page_Load(object sender, EventArgs e) </span><br /><span style="color:#3333ff;">{ </span><br /><span style="color:#3333ff;">RepeaterPager.Ods= Repeater1; </span><br /><span style="color:#3333ff;">RepeaterPager.Rep= ObjectDataSource1; </span><br /><span style="color:#3333ff;">}</span><br /><strong>4- Build and run :)</strong>Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com0tag:blogger.com,1999:blog-7877630238664826501.post-26913884998047056282009-05-23T07:35:00.000-07:002009-05-24T00:51:57.490-07:00How To: Use Office 2007 OCR Using C#<strong>I'll Show you how to read text from any image.<br /></strong><br />If you have Office 2007 installed, the OCR component is available for you to use. The only dependency that's added to your software is Office 2007. Requiring Office 2007 to be installed in order for your software to work may or may not fit a situation. But if your client can guarantee that machines that your software will run on have Office 2007 installed, you're gold. I've encountered many situations where this is the case. I've even encountered a few situations where clients were willing to install Office 2007 in order to use my applications.<br /><br /><strong>Steps:</strong><br /><br /><strong>1- add Reference to Office 2007 Component:</strong><br /><br />The name of the COM object that you need to add as a reference is Microsoft Office Document Imaging 12.0 Type Library. By default, Office 2007 doesn't install it. You'll need to make sure that it's added by using the Office 2007 installation program. Just run the installer, click on the Continue button with the "Add or Remove Features" selection made, and insure that the imaging component is installed as shown in the figure to the right.<br />Important Note:The name of the COM object that you need to add as a reference is Microsoft Office Document Imaging 12.0 Type Library. By default, Office 2007 doesn't install it. You'll need to make sure that it's added by using the Office 2007 installation program. Just run the installer, click on the Continue button with the "Add or Remove Features" selection made, and insure that the imaging component is installed.<br /><br /><strong>2- Create Windows Application Using C#:<br /></strong><br />from Visual Studio Solution Explorer >> right click on refferences>> select com tab>> then select (Microsoft Office Document Imaging 12.0 Type Library)<br /><br /><strong>3- Put Button in your Form then put the following code:<br /></strong><br /><span style="color:#000099;">OpenFileDialog openFileDialog = new OpenFileDialog(); </span><br /><span style="color:#000099;">openFileDialog.ShowDialog();</span><br /><span style="color:#000099;"><br />MODI.Document md = new MODI.Document(); </span><br /><span style="color:#000099;">md.Create(openFileDialog.FileName); </span><br /><span style="color:#000099;">md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);</span><br /><span style="color:#000099;"><br />MODI.Image image = (MODI.Image)md.Images[0]; </span><br /><span style="color:#000099;">MessageBox.Show(image.Layout.Text, "The Selected Image Text is:");</span><br /><br /><strong>4- Run The Application then press the button and select any image has text.</strong><br /><br /><strong><em>Conclusion:</em><br /><em></em></strong><br /><span style="font-family:arial;font-size:85%;"><strong>I made a big sample application for Office OCR, if anyone interested, you can contact me on :</strong></span><br /><br /><a href="mailto:waleed.hussein.eg@gmail.com">waleed.hussein.eg@gmail.com</a>Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com6tag:blogger.com,1999:blog-7877630238664826501.post-34004056924525631162009-05-22T08:42:00.000-07:002009-05-24T00:55:15.824-07:00How To: Sending Email Using C#<strong>in this article I'll show you how can you send mail using windows application<br /></strong>I'm using gmail becouse it allowed sending and recieving Emails and you need to make some configurations like:<br />Host Name: smtp.gmail.com<br />Port Number: 587<br />Your Email Address: <a href="mailto:yourEmail@gamil.com">yourEmail@gamil.com</a><br />your Password: your Email Password<br />SSL:true (becouse gmail using ssl)<br /><br />Let's start...<br /><br />Create Windows Application using C# :<br />Create Form Like the Below Form with Controls<br /><br /><span style="color:#000066;"><strong>Important Note Controls Names Will be Like:</strong></span><br /><strong><span style="color:#000066;"></span></strong><br /><strong>textbox =txt...</strong><br /><strong>label=lbl...</strong><br /><strong>button=btn...</strong><br /><br /><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWhs0MN0t5397xd_BLFNfRvNrcyoP9t6FeCV_k_6q4XIRkr8aurgGYQig88Oh-EBPqIiqPNTcc5I3HsiSNcE8_RXPwZQwybpEZ3CiXyodYwOXklo4oGsSJMVJHTAWueibKHrHE26L47w-T/s1600-h/How+To+Send+Mail.JPG"><img id="BLOGGER_PHOTO_ID_5338674507386156642" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; HEIGHT: 267px; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWhs0MN0t5397xd_BLFNfRvNrcyoP9t6FeCV_k_6q4XIRkr8aurgGYQig88Oh-EBPqIiqPNTcc5I3HsiSNcE8_RXPwZQwybpEZ3CiXyodYwOXklo4oGsSJMVJHTAWueibKHrHE26L47w-T/s320/How+To+Send+Mail.JPG" border="0" /></a><br /><br /><span style="color:#000099;">using System.Net;<br />using System.Net.Mail;</span><br /><br />then create some properities :<br />you can put them in seperated class but I'm putted them in the same form because it's a sample<br /><br /><span style="color:#000099;">public string MailFrom { get; set; }<br />public string MailTo { get; set; }<br />public string MailBody { get; set; }<br />public string MailSubject { get; set; }<br />public string AttachmentFile { get; set; }<br />public string HostName { get; set; }<br />public int PortNumber { get; set; }<br />public string EmailAddress { get; set; }<br />public string EmailPassword { get; set; }<br />public bool SSL { get; set; }</span><br /><br />then create method for sending mail:<br /><br /><span style="color:#000099;">public void SendingMail()<br />{<br />MailMessage mailMessage = new MailMessage(MailFrom,MailTo,MailSubject,MailBody);<br />Attachment fileAttachment = new Attachment(AttachmentFile);<br />mailMessage.Attachments.Add(fileAttachment);<br />SmtpClient smtpClient = new SmtpClient(HostName,PortNumber);<br />smtpClient.Credentials = new NetworkCredential(EmailAddress,EmailPassword);<br />smtpClient.EnableSsl = SSL;<br />smtpClient.Send(mailMessage);<br />}</span><br /><span style="color:#000099;"></span><br />in attachment button put the following code:<br /><br /><span style="color:#000099;">private void btnAttachment_Click(object sender, EventArgs e)<br />{<br />OpenFileDialog fileDialog = new OpenFileDialog();<br />fileDialog.ShowDialog();<br />lblAttachment.Text = fileDialog.FileName;<br />}</span><br /><span style="color:#000099;"></span><br />in Send Mail Button put the following code:<br /><br /><span style="color:#000099;">private void btnSendMail_Click(object sender, EventArgs e)<br />{<br />try<br />{<br />MailFrom = txtMailAddress.Text; ;<br />MailTo = txtTo.Text;<br />MailBody = txtBody.Text;<br />MailSubject = txtSubject.Text;<br />AttachmentFile = lblAttachment.Text;<br />HostName = txtHostName.Text;<br />PortNumber = Convert.ToInt16(txtPortNo.Text);<br />EmailAddress = txtMailAddress.Text;<br />EmailPassword = txtMailPassword.Text;<br />SSL = chkSSL.Checked;<br />SendingMail();<br />MessageBox.Show("Sending Mail Succeeded");<br />}<br />catch (Exception ex)<br />{<br />MessageBox.Show(ex.Message);<br />}<br />}</span>Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com4tag:blogger.com,1999:blog-7877630238664826501.post-15344786649313468932009-04-14T06:13:00.000-07:002009-05-24T00:29:34.252-07:00How to: Create Database Using C#<strong>In this article I will show you How to Create Database and Tables at run time using C#:</strong><br /><br />I’ll Use ADOX Component to Create Database and Tables.<br /><br />First Create Windows Application Using C#.<br /><br />In Solution Explorer > References > Right Click > Add Reference<br />In Com Section Select (Microsoft ADO Ext. 2.8 for DDL and Security) then press Ok.<br /><br /><strong>using ADOX;</strong><br /><br /><strong>In Form Load Event Put the Following Code:</strong><br /><strong><br /></strong>Catalog catlog=new Catalog();<br />string tempStr;<br />string fileName = @"C:\Sample.mdb";<br /><br /><br /><span style="color:#009900;">//Create Connection String<br /></span>tempStr = "Provider=Microsoft.Jet.OLEDB.4.0;";<br />tempStr += "Data Source=" + fileName + ";Jet OLEDB:Engine Type=5";<br /><br /><span style="color:#009900;">//Create Database</span><br />catlog.Create(tempStr);<br /><br /><span style="color:#009900;">//Create Defects Table<br /></span>Table tblDefects=new Table();<br />tblDefects.Name = "Defects";<br /><br /><span style="color:#009900;">//Add Table Cloumns</span><br />tblDefects.Columns.Append("Date", DataTypeEnum.adVarWChar, 50);<br />tblDefects.Columns.Append("Time", DataTypeEnum.adVarWChar, 50);<br />tblDefects.Columns.Append("Defect-Code", DataTypeEnum.adVarWChar, 50);<br />tblDefects.Columns.Append("Start-Finish", DataTypeEnum.adVarWChar, 50);<br />tblDefects.Columns.Append("ClockStart", DataTypeEnum.adVarWChar, 50);<br />tblDefects.Columns.Append("ClockEnd", DataTypeEnum.adVarWChar, 50);<br />tblDefects.Columns.Append("Pilot", DataTypeEnum.adVarWChar, 50);<br />tblDefects.Columns.Append("Logger", DataTypeEnum.adVarWChar, 50);<br />tblDefects.Columns.Append("Payout", DataTypeEnum.adVarWChar, 50);<br />tblDefects.Columns.Append("Lat", DataTypeEnum.adVarWChar, 50);<br />tblDefects.Columns.Append("Long", DataTypeEnum.adVarWChar, 50);<br />tblDefects.Columns.Append("Depth", DataTypeEnum.adVarWChar, 50);<br />tblDefects.Columns.Append("Comment", DataTypeEnum.adVarWChar, 250);<br />tblDefects.Columns.Append("Pics", DataTypeEnum.adVarWChar, 50);<br /><br /><span style="color:#009900;">//Append Tables into Database<br /></span>catlog.Tables.Append(tblDefects);<br /><br /><span style="color:#009900;">//Create Log Table</span><br />Table tblLog=new Table();<br />tblLog.Name = "Log";<br /><br /><span style="color:#009900;">//Add Table Cloumns<br /></span>tblLog.Columns.Append("Date", DataTypeEnum.adVarWChar, 50);<br />tblLog.Columns.Append("Time", DataTypeEnum.adVarWChar, 50);<br />tblLog.Columns.Append("Pilot", DataTypeEnum.adVarWChar, 50);<br />tblLog.Columns.Append("Logger", DataTypeEnum.adVarWChar, 50);<br />tblLog.Columns.Append("Payout", DataTypeEnum.adVarWChar, 50);<br />tblLog.Columns.Append("Lat", DataTypeEnum.adVarWChar, 50);<br />tblLog.Columns.Append("Long", DataTypeEnum.adVarWChar, 50);<br />tblLog.Columns.Append("Depth", DataTypeEnum.adVarWChar, 50);<br /><br /><span style="color:#009900;">//Append Tables into Database<br /></span>catlog.Tables.Append(tblLog);<br /><br /><span style="color:#009900;">//release the com objects properly and in the proper order<br /></span>System.Runtime.InteropServices.Marshal.FinalReleaseComObject(tblDefects);<br />System.Runtime.InteropServices.Marshal.FinalReleaseComObject(tblLog);<br />System.Runtime.InteropServices.Marshal.FinalReleaseComObject(catlog.Tables);<br />System.Runtime.InteropServices.Marshal.FinalReleaseComObject(catlog.ActiveConnection);<br />System.Runtime.InteropServices.Marshal.FinalReleaseComObject(catlog);Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com1tag:blogger.com,1999:blog-7877630238664826501.post-84532033054529373092009-02-25T10:13:00.000-08:002009-05-24T00:48:01.033-07:00How To: Capture Screen Image using C#In this article I will show you How to Capture Screen Image using C#.<br /><br />- Create Windows Application Using C#.<br />- Add the following code :<br />using System.Drawing;<br />using System.Drawing.Imaging;<br /><br />private void Form1_Load(object sender, EventArgs e)<br />{<br />ImageBitmap.Save(@"C:\ScreenImage.jpg");<br />}<br /><br />public Bitmap ImageBitmap<br />{<br />get<br />{<br />Rectangle screenShot;<br />Bitmap sBit;<br /><br />//Drawing a Rectangle<br />screenShot = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;<br /><br />//Set image size and format<br />sBit = new Bitmap(screenShot.Width, screenShot.Height, PixelFormat.Format32bppArgb);<br />Graphics sGraphic = Graphics.FromImage(sBit);<br /><br />//Capture From Screen<br />sGraphic.CopyFromScreen(screenShot.Left, screenShot.Top, 0, 0, screenShot.Size);<br /><br />return sBit;<br />}<br />}Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com1tag:blogger.com,1999:blog-7877630238664826501.post-73405001047326493442009-02-25T04:13:00.000-08:002009-05-24T07:31:34.829-07:00How to Connect to Team Foundation Server Using C#In this article I will show you how to connect to Team Foundation Server and add work item via code<br />First thing you must install TFS SDK, you can download the Team Foundation Server SDK from the below link.<br /><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=7e0fdd66-698a-4e6a-b373-bd0642847ab7&DisplayLang=en">http://www.microsoft.com/downloads/details.aspx?FamilyID=7e0fdd66-698a-4e6a-b373-bd0642847ab7&DisplayLang=en</a><br />Steps:<br />1- Create windows or web Application<br />2- Add References for :<br />Microsoft.TeamFoundation.Client<br />Microsoft.TeamFoundation.WorkItemTracking.Client<br />3- The below code will help you to work with Team Foundation Server<br /><br />using Microsoft.TeamFoundation.Client;<br />using Microsoft.TeamFoundation.WorkItemTracking.Client;<br /><br />// declaration variable<br />private NetworkCredential networkCredential = new NetworkCredential("enter here User Name", "enter here password", "enter here domian");<br />private Uri uri = new Uri("enter here TFS URL");<br />string projectName="enter here TFS prject name";<br />string worktemType = "enter here Work Item Type";<br /><br />// Set Authentication To TFS<br />TeamFoundationServer teamFoundationServer = new TeamFoundationServer(uri.AbsoluteUri, networkCredential);<br />teamFoundationServer.Authenticate();<br />//Add Work Item<br />WorkItemStore wis = (WorkItemStore)teamFoundationServer.GetService(typeof(WorkItemStore));<br />Project tfsProject = wis.Projects[projectName];<br />WorkItemType wiType = tfsProject.WorkItemTypes[workItemType];<br />WorkItem workItem = new WorkItem(wiType);<br />workItem.Title = "Test Work Item";<br />workItem.Description = "Work Item Description";<br />workItem.Save();Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com7tag:blogger.com,1999:blog-7877630238664826501.post-60939869852319204072009-02-03T01:06:00.001-08:002009-05-24T01:05:33.522-07:00How To: Encrypt and Decrypt string Using C#<p align="left">I think Any Developer need to protect his data from nasty people<br />Ex. We will assume we have an application (windows application – web application ….etc) will connect to<br />Active directory or Team Foundation Server or any application need authentication to connect to it<br />First thing any developer should thinking about how I made my application secured<br /><br />So when we pass the credentials will pass it Encrypted and from another side will decrypt these credentials.<br />In this article I’ll show you how to encrypt any string and decrypt it.<br />Create a new windows application using C# the design will be something like the below image:</p><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLnjDucASz2eUBces8eO3E2Yl2-4mBCsy_dAkrjMzBfCg3duOyOauGrBOnbExTrKawccB91u7tXqe0B2CUyqeVjctXpylgXOjOwan_j8803ZdVIsvGLU9yfNbpYRmAKyh64y_fRvwQjcO3/s1600-h/EncryptionTool.JPG"><img id="BLOGGER_PHOTO_ID_5298495074732002754" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 320px; CURSOR: hand; HEIGHT: 178px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLnjDucASz2eUBces8eO3E2Yl2-4mBCsy_dAkrjMzBfCg3duOyOauGrBOnbExTrKawccB91u7tXqe0B2CUyqeVjctXpylgXOjOwan_j8803ZdVIsvGLU9yfNbpYRmAKyh64y_fRvwQjcO3/s320/EncryptionTool.JPG" border="0" /></a><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />using System;<br />using System.Collections.Generic;<br />using System.ComponentModel;<br />using System.Data;<br />using System.Drawing;<br />using System.Linq;<br />using System.Text;<br />using System.Windows.Forms;<br />using System.Security.Cryptography;<br />using System.IO;<br /><br />namespace RsaEncryption<br />{<br />public partial class Main : Form<br />{<br />public Main()<br />{<br />InitializeComponent();<br />}<br /><br /><br />private static string sKey = "UJYHCX783her*&5@$%#(MJCX**38n*#6835ncv56tvbry(&#MX98cn342cn4*&X#&";<br /><br />public static string Encrypt(string sPainText)<br />{<br />if (sPainText.Length == 0)<br />return (sPainText);<br />return (EncryptString(sPainText, sKey));<br />}<br /><br />public static string Decrypt(string sEncryptText)<br />{<br />if (sEncryptText.Length == 0)<br />return (sEncryptText);<br />return (DecryptString(sEncryptText, sKey));<br />}<br /><br /><br />protected static string EncryptString(string InputText, string Password)<br />{<br />// "Password" string variable is nothing but the key(your secret key) value which is sent from the front end.<br />// "InputText" string variable is the actual password sent from the login page.<br />// We are now going to create an instance of the<br />// Rihndael class.<br />RijndaelManaged RijndaelCipher = new RijndaelManaged();<br />// First we need to turn the input strings into a byte array.<br />byte[] PlainText = System.Text.Encoding.Unicode.GetBytes(InputText);<br />// We are using Salt to make it harder to guess our key<br />// using a dictionary attack.<br />byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString());<br />// The (Secret Key) will be generated from the specified<br />// password and Salt.<br />//PasswordDeriveBytes -- It Derives a key from a password<br />PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, Salt);<br />// Create a encryptor from the existing SecretKey bytes.<br />// We use 32 bytes for the secret key<br />// (the default Rijndael key length is 256 bit = 32 bytes) and<br />// then 16 bytes for the IV (initialization vector),<br />// (the default Rijndael IV length is 128 bit = 16 bytes)<br />ICryptoTransform Encryptor = RijndaelCipher.CreateEncryptor(SecretKey.GetBytes(16), SecretKey.GetBytes(16));<br />// Create a MemoryStream that is going to hold the encrypted bytes<br />MemoryStream memoryStream = new MemoryStream();<br />// Create a CryptoStream through which we are going to be processing our data.<br />// CryptoStreamMode.Write means that we are going to be writing data<br />// to the stream and the output will be written in the MemoryStream<br />// we have provided. (always use write mode for encryption)<br />CryptoStream cryptoStream = new CryptoStream(memoryStream, Encryptor, CryptoStreamMode.Write);<br />// Start the encryption process.<br />cryptoStream.Write(PlainText, 0, PlainText.Length);<br />// Finish encrypting.<br />cryptoStream.FlushFinalBlock();<br />// Convert our encrypted data from a memoryStream into a byte array.<br />byte[] CipherBytes = memoryStream.ToArray();<br />// Close both streams.<br />memoryStream.Close();<br />cryptoStream.Close();<br />// Convert encrypted data into a base64-encoded string.<br />// A common mistake would be to use an Encoding class for that.<br />// It does not work, because not all byte values can be<br />// represented by characters. We are going to be using Base64 encoding<br />// That is designed exactly for what we are trying to do.<br />string EncryptedData = Convert.ToBase64String(CipherBytes);<br />// Return encrypted string.<br />return EncryptedData;<br />}<br /><br />protected static string DecryptString(string InputText, string Password)<br />{<br />try<br />{<br />RijndaelManaged RijndaelCipher = new RijndaelManaged();<br />byte[] EncryptedData = Convert.FromBase64String(InputText);<br />byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString());<br />PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, Salt);<br />// Create a decryptor from the existing SecretKey bytes.<br />ICryptoTransform Decryptor = RijndaelCipher.CreateDecryptor(SecretKey.GetBytes(16), SecretKey.GetBytes(16));<br />MemoryStream memoryStream = new MemoryStream(EncryptedData);<br />// Create a CryptoStream. (always use Read mode for decryption).<br />CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor, CryptoStreamMode.Read);<br />// Since at this point we don't know what the size of decrypted data<br />// will be, allocate the buffer long enough to hold EncryptedData;<br />// DecryptedData is never longer than EncryptedData.<br />byte[] PlainText = new byte[EncryptedData.Length];<br />// Start decrypting.<br />int DecryptedCount = cryptoStream.Read(PlainText, 0, PlainText.Length);<br />memoryStream.Close();<br />cryptoStream.Close();<br />// Convert decrypted data into a string.<br />string DecryptedData = Encoding.Unicode.GetString(PlainText, 0, DecryptedCount);<br />// Return decrypted string.<br />return DecryptedData;<br />}<br />catch (Exception exception)<br />{<br />return (exception.Message);<br />}<br />}<br /><br /><br />private void btnEncrypt_Click(object sender, EventArgs e)<br />{<br />txtEncryption.Text= Encrypt(txtPassword.Text);<br />}<br /><br />private void btnDecrypt_Click(object sender, EventArgs e)<br />{<br />MessageBox.Show(Decrypt(txtEncryption.Text));<br />}<br /><br /><br />}<br />}Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com9tag:blogger.com,1999:blog-7877630238664826501.post-71883810768833602062009-01-11T10:09:00.000-08:002009-05-24T01:08:04.263-07:00Get Active Directory Connection String1- create new C# windows application<br />2- Put Text Box on the Form<br />3- on Form load Event Copy the Below Code:<br /><br /><span style="color:#ff0000;">DirectoryEntry root = new DirectoryEntry("LDAP://RootDSE");<br />using (root)<br />{<br />string dnc = root.Properties["defaultNamingContext"][0].ToString();<br />string server = root.Properties["dnsHostName"][0].ToString();<br />string adsPath = String.Format(<br />"LDAP://{0}/{1}",<br />server,<br />dnc<br />);<br />textBox1.Text = adsPath;<br />}<br /></span>4- don't forget to make <span style="color:#ff0000;">using System.DirectoryServices;</span><br /><span style="color:#ff0000;"><span style="color:#000000;">- Add Reference for</span> System.DirectoryServices</span><br /><span style="color:#000000;">5- you must run the application On a machine has a domain</span>Waleed Elkothttp://www.blogger.com/profile/00759403841530818590noreply@blogger.com5