Friday, April 29, 2011

CrystalReportViewer is missing in VS.Net 2010 toolbox

After installing Crystal Report for Visual Studio.Net 2010

then add the reference of following dlls
CrystalDecisions.Windows.Forms.dll (Main)

and build the project then u will be able to see CrystalReportView control in toolbox.

Ping a url without opening in browser.

 private void BrowseUrl(string url)
                HttpWebRequest loHttp = (HttpWebRequest)WebRequest.Create(url);

                // *** Return the Response data
                HttpWebResponse loWebResponse = (HttpWebResponse)loHttp.GetResponse();

                Encoding enc = Encoding.GetEncoding(1252);  // Windows-1252 or iso-
                if (loWebResponse.ContentEncoding.Length > 0)
                    enc = Encoding.GetEncoding(loWebResponse.ContentEncoding);

                StreamReader loResponseStream =
                    new StreamReader(loWebResponse.GetResponseStream(), enc);

                string response = loResponseStream.ReadToEnd();

                if (response.Length != 0)
                   // You can write this response to some textbox here also

            catch (Exception ex)
                throw ex;

Friday, April 8, 2011

How to scroll to bottom in a textbox in C#

Use function called ScrollToCaret of textbox. You need to first set the caret position to the end of the text box, then call the ScrollToCaret function.
Here's how to do it:
        //move the caret to the end of the text
        textBox.SelectionStart = textBox.TextLength;
        //scroll to the caret