C#: Passing data to BackgroundWorker DoWork Event

Normally, you call the RunWorkerAsync() without an argument to start the background worker. Sometimes you might want to pass some data into the DoWork() function. All you have to do is simply do: RunWorkerAsync(some data) For example, the following code pass an array of string: string[] list = {"one", "two", "three"}; MyBackgroundWorker1.RunWorkerAsync(List); Then you have […]

C#: Simple Way to Upload a File

In this example, I will show you how to easily upload a file to your web server via FTP. You’d need to add using System.Net; Make a FTP connection and read a file into stream, then writes to FTP. Important Note: because you’re casting WebRequest to a FtpWebRequest, your Address need to start with ftp://www.hostname.com, […]

C#: Simple way to parse XML string to get Value from the tag

C# makes it very easy to parse a xml file or string. For example, if you want to parse the following xml file, looking just for the value of the tag called “score”: <?xml version=”1.0″ encoding=”UTF-8″?> <results> <status>OK</status> <url>http://www.monkeycancode.com/</url> <totalTransactions>1</totalTransactions> <language>english</language> <mixed>1</mixed> <score>0.111642</score> <type>positive</type> </results> This will work even with tag element that is in […]

C#: how to write in-line code in new Event Handler Declaration

Normally, you need to declare a new Event Handler and give this new event handler a name, then write the function inside the new event handler function to complete the code. However, you can skip that by writing in-line code inside a declaration of new event handler. copyToolStripMenuItem.Name = "copyToolStripMenuItem"; copyToolStripMenuItem.Size = new System.Drawing.Size(152, 22); […]