devxlogo

.NET

Strip HTML Content from a String

To?string?HTML?tags,?use?HttpUtility???s?HTMLDecode?method?with?a?RegEx?expression.?HTMLDecode?is?available?in?System.Web?assembly. string?htmlText?=?@”Decision?Making?Techniques:?Why?should?you?be?prepared”; string?plainText?=?string.Empty; if?(!string.IsNullOrWhiteSpace(htmlText)) { ?????plainText?=?Regex.Replace(HttpUtility.HtmlDecode(htmlText),?@””,?string.Empty).Trim(); }

Show the Page Download Status in a WebBrowser Control

The Webbrowser control provides us with the “ProgressChanged” event. We can use the “CurrentProgress” and “MaximumProgress” Properties of the WEbBrowserProgressChangedEventArgs in this method to determine the percentage of the page

List all Environment Variables

The system variables are exposed through the GetEnvironmentVariables method in the System.Environment class. var environmentVariables = System.Environment.GetEnvironmentVariables();foreach (var ev in environmentVariables){ DictionaryEntry de = (DictionaryEntry) ev; Console.WriteLine(string.Format(“Key: {0}, Value: {1}”,

Generate Random Passwords

Use the following method to generate random passwords. private string GenerateRandomPassword(int minLength, int maxLength) { StringBuilder randomPassword = new StringBuilder(); Random rand = new Random((int)DateTime.Now.Ticks); int randLength = rand.Next(minLength, maxLength);

Check if an HttpRequest is an Ajax Request

A quick way to check if an HTTP Request is an Ajax request is by examining the X-Requested-With Header value. Please see below: bool isAjaxRequest = request.Headers[“X-Requested-With”] != null &&

Check if a String Contains a Phrase

The following snippet will allow you quickly determine whether or not a specified phrase exists in a string: If (!String.IsNullOrEmpty(STRINGTOCHECK.ToString()) && STRINGTOCHECK.ToString().ToLower().Contains(“PHRASETOSEARCHFOR”)){//Found}Else{//Not Found}

Determine Whether or Not a Form Is Open

Sometimes in the myriad of forms, it can become quite difficult figuring out whether or not a form has already been loaded and if is still open or not. To

Bypassing a Dialog Window’s DialogResult

Whenever you show a Modal Dialog a DialogResult is expected. This DialogResult can be OK, Cancel, Yes, No and so forth. Now, imagine this scenario: You show a Modal Dialog