April 2, 2009
C# FTP Demo
How to use the FTP functions built-in to C#
This is a more intermediate video.
What you will learn:
1) How to create a reuseable FTPFunction class library (with three static methods: Upload, Download, GetFileList.
2) How to call the function library from both a Windows form and a Console program.
First, I found some sample FTP code from this site:
http://aspalliance.com/1187_Building_a_Simple_FTP_Application_Using_C_20
I wrote the console program, because I wanted to schedule a nightly download from an FTP site in order to back-up an SQL server database backup (from my dedicated server to my laptop).
I decided to package the three routines in a class library, so it could be a shareable and reuseable DLL.
I then am able to call it from various other programs (and in the video, I do this from a Windows form, and a Console Command-Line program).
Once the code was packaged in the .DLL, it was easy to call it like this:
Code for you to copy:
|
I created Download, Upload, and GetFileList as static methods, so they can be called without instantiating a class.
Two videos coming shortly…
Filed under FTP by Administrator
Using “Try/Catch” in C#
A Try/Catch block is the error handling mechanism for .NET.
What you will learn here:
1) How to wrap your code in a “Try” statement
2) How to catch and display errors in the “Catch” statement
3) The three major properties of the Exception class (Message, Source, StackTrace) and the ToString() method.
Code for you to copy:
|
Video Demonstration:
Part 1 of 2
Part 2 of 2
Filed under C# Try/Catch by Administrator
Using “MessageBox” in C#
A MessageBox is basically a pop-up box that shows a message to the user. It may or may not provide buttons to get feedback from the user.
What you will learn here:
1) How to use MessageBox.Show with various parameters
2) How to find out which button the user clicked-on in the MessageBox
3) How to change the caption of the MessageBox
Code for you to copy:
|
Video Demonstration:
Filed under C# MessageBox by Administrator
Use of Lists in C#
What you will learn here:
1) Syntax is “List
2) How to add items to a List
3) How to use a “foreach” statement to loop through a list
4) Our specific example is a subroutine (method) that receives a List of numbers, and returns only the odd numbers in that List.
This video is a solution to a “quiz” I was given in an interview. A developer gave me this method signature, and asked me to scratch out the code to accomplish returning all the odd numbers in the list (at first I thought he said all the odd numbered items in the list).
|
I had a “brain cloud” when doing this demo. I was thinking I could divide by 2 to find out if the number was even. I totally forgot about “modulo” division, which is what my subconscious was thinking. If you use a backslash instead of a forward slash, then the remainder will be returned. If you do modulo division dividing by 2, and the remainder is zero, then you have an even number, otherwise an odd number. That’s a more elegant way to do the odd/even test than what I did in the video below.
Code for you to copy:
|
Video Demonstration:
Filed under C# Lists by Administrator

