Posts

Donate

Retrieve Record Counts For All Tables In MySQL DB

Reference: Get Record Counts for All Tables in MySQL

Using Proxy With WebClient In VB.NET

Here is a snippet to use WebProxy. This is useful for scraping or other webrequest activities. Dim webclient As New System.Net.WebClient Try 'true for bypassOnLocal webclient .Proxy = New System.Net.WebProxy( "180.95.129.232:80" , true ) wc.OpenRead( "http://yoursite.com" ) lblStatus.Text = "ok" Catch lblStatus.Text = "error proxy" End Try

Format Query Result By Count() With Comma Using Format() In MySQL Database

I played around with MySQL count() statement. I found it annoying that the count() will simply return whole numbers. Example: the total record of a table is 32,272. In MySQL SQL, this will simply return 32272. Below are two sql scripts. The first one returns whole number,while the second query returns comma separated number. ENJOY!!!! select count (*) as num_records_notformatted from mytable where name like '%j%' ; Solution: select format( count (id),0) as num_records_formatted from mytable where name like '%j%' ;

How To Set The Scrollbars In WPF Textbox

You can set the scrollbars in a WPF TextBox control using it's properties: HorizontalScrollBarVisibility= "Visible" VerticalScrollBarVisibility= "Auto" or using the ScrollView class: ScrollViewer.HorizontalScrollBarVisibility= "Auto" ScrollViewer.VerticalScrollBarVisibility= "Auto"

Control.InvokeRequired Not Found Or Missing In WPF

Hello, I was doing a little WPF threading recently which involved changing my codes from Winforms to WPF. Surprisingly, I was not able to find the code below in the intellisense: Control.Dispatcher.CheckAccess() After googling, I found this link: Why is Dispatcher.CheckAccess() hidden from intellisense? I wonder why Microsoft hid some features on intellisense. Or it could be a bug. Regards!!!

Webclient - The remote server returned an error: (403) Forbidden

Using downloadstring of webclient returns an error as stated by the post title. The solution was to add user agent header to the webclient headers. The value of user agent can be found in the mozilla firebug. Solution: string URL = string .Format(your_url); newWebClient.Headers.Add( "user-agent" , "Mozilla/5.0 (Windows NT 6.1; rv:2.0) Gecko/20100101 Firefox/4.0 "); string pageSource = newWebClient.DownloadString(URL); pageSource = System.Web.HttpUtility.HtmlDecode(pageSource);

How To Show External IP Address Using C# And WebClient

I experimented a snippet to get my ISP provided IP address using whatismyip. Using tutorials or code snippets from links, the web request just returned a 404 error. After reading the whatismyip API again,they have changed their automation URL. Below is the code snippet. //previous URL present on most tutorials which is not working //string whatIsMyIp = "http://www.whatismyip.com/automation/n09230945.asp"; //updated URL from whatismyip API string whatIsMyIp = "http://automation.whatismyip.com/n09230945.asp" ; WebClient wc = new WebClient(); UTF8Encoding utf8 = new UTF8Encoding(); string requestHtml = "" ; requestHtml = utf8.GetString(wc.DownloadData(whatIsMyIp));

How To Convert Epoch Time To DateTime In C#

Good morning awesome programmers, Me and my fellow teammate encountered a scenario to convert epoch time to datetime. The solution can be found in stack overflow. private void Form1_Load( object sender, EventArgs e) { //long tms = 1308139229; long tms = 1308143650; DateTime dt = FromUnixTime(tms); MessageBox.Show(dt.ToShortDateString()); } public DateTime FromUnixTime( long unixTime) { var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); return epoch.AddSeconds(unixTime); }

Sorting List<T> Generic Collection String In C#

This example uses List generic collection and will sort names in descending order. Names with New will be displayed on top of the list. This is applicable if you will be displaying products names with NEW in it's product name as recently displayed. List< string > Names = new List< string >(); private void FListSort_Load( object sender, EventArgs e) { Names.Add( "Mike" ); Names.Add( "John" ); Names.Add( "Titch" ); Names.Add( "Harold" ); Names.Add( "Klent" ); Names.Add( "Thomas New" ); Names.Add( "Mary" ); Names.Add( "Fultron New" ); Names.Add( "Khayce" ); Names.Add( "Tim" ); Names.Add( "Joker New" ); Names.Add( "Linda" ); Names.Add( "Arthur New" ); Names.Add( "Baby Lee Jones"

Posting Data To WebBrowser Control In C#

Good day! Basically, it is possible to post data to web browser control using C#. The code below, was referenced from MSDN, but i slightly modified some of it's functionalities. string url = "http://example.com" ; string postData = String.Format( "city=DC&Page={0:00}" ,pageNum); byte [] Post = Encoding.UTF8.GetBytes(postData ); string AdditionalHeaders = "Content-Type: application/x-www-form-urlencoded" ; //wbSample is the web browser control //the WebNavigate method is just a simple method i created //which simply assigns url to the browser, the post data and additional headers WebNavigate(wbSample , ListURL, "" , Post, AdditionalHeaders);

Donate