How to Copy, Delete a File in C# .NET

Saturday, 22 September 2012

You can copy a file quite easily. It's done with the File class of System.IO. Let's see how. First create a new folder on your C drive. Give it the name copiedFiles.
Add a new button to your form. Double click to get at the code, and set up the following files and directory paths:

string fileToCopy = "C:\\test1.txt";
string newLocation = "C:\\copiedFiles\\test1.txt";
string folderLocation = "C:\\copiedFiles";

So the file we want to copy is test1.txt and it is in the root folder of the C drive. We want to copy it to a new location. The folder (Directory) we want to copy it to is called copiedFiles. We added a Folder Location, because we want to check if this Directory exists.
To copy a file, you use the Copy method of the File class:

System.IO.File.Copy( fileToCopy, newLocation );

In between the round brackets of Copy, you need a file to copy and the new location of the file you're trying to copy.
When the error checking is done as well, our code looks like this:

C# code to copy a file

The code checks to see if the Directory exists. If it does, then we check to see if the file exist. If all is OK, then we go ahead and copy the file.

Add the code to your own and try it out. When you click your button, you should see the "File Copied" message box appear. If you look in the copiedFiles folder that you created, you should see the test1.txt file there. 

Move a File

To move a file to a new location, you would use the Move method of the File class:
System.IO.File.Move( fileToMove, fileLocation );
Everything else is the same: type a file to move between the round brackets of theMove method. Then, after a comma, add the new location.
Don't forget to add your error checking as well!

Delete a File

To delete a file from your computer, you can use the Delete method of the File class:
System.IO.File.Delete( file_path );
In between the round brackets of Delete, you need the name and path of the file you are trying to get rid of. Be very careful when trying this one out because it really does delete it. You won't find the file in the Recycle bin.

Drawing Polygons in C# .NET


                    You can also draw irregular shapes, like Polygons. To do that, you set up a series of points, and hand them to the DrawPolygon method.

                    The first thing to do is to set up an array of points:

Point[] polygonPoints = new Point[5];
              
                    This sets up a new point array called polygonPoints. We're specified 5 sets of points. The points are X, Y coordinates. X is how far to the left you want the point and Y is how far down. You set them up like this:

polygonPoints[0] = new Point(113, 283);
polygonPoints[1] = new Point(70, 156);
polygonPoints[2] = new Point(180, 70);
polygonPoints[3] = new Point(290, 156);
polygonPoints[4] = new Point(250, 283);

                  So each slot in the array is filled with a new point. In between the round brackets of Point, you add your X, Y coordinates.
Once you have your points array, you can hand it to the DrawPolygon method:

surface.DrawPolygon( pen1, polygonPoints );

                After specifying what you want to draw on (surface, for us), you type a dot followed by DrawPolygon. In between the round brackets of DrawPolygon you first need a pen. Then you need your points array. Note that the brackets of the array are not needed.
If you want to fill your polygon, you can use the FillPolygon method:

surface.FillPolygon( brushOne, polygonPoints );

               FillPolygon needs a brush, and the points array again. When the above code is run, it will produce the following polygon:



What you need to get started with PHP

                     Before you can write and test your PHP scripts, there's one thing you'll need - a server! Fortunately, you don't need to go out and buy one. In fact, you won't be spending any extra money. That's why PHP is so popular! But because PHP is a server-sided scripting language, you either have to get some web space with a hosting company that supports PHP, or make your computer pretend that it has a server installed. This is because PHP is not run on your PC - it's executed on the server. The results are then sent back to the client PC .
                    


Apple Users

If you have OS X, then try these sites to get up and running with PHP:
http://www.onlamp.com/pub/a/mac/2001/12/07/apache.html
http://www.entropy.ch/software/macosx/php/
What you're doing here is getting the apache server up and running, so that you can run PHP scripts offline. Pay particular attention to where files are stored, and to the "localhost" address.

Linux Users

There are quite a few sites out there to help Linux users get up and running with the Apache server and PHP. Here are three sites that are worth checking out:
http://en.wikipedia.org/wiki/LAMP_(software_bundle)
http://www.php-mysql-tutorial.com/wikis/php-tutorial/installing-php-and-mysql.aspx
http://www.phpfreaks.com/tutorials/12/0.php
If you know any better ones, we'd be interested in hearing from you!

Windows Users

OK, back to Wampserver and Windows. First, you need to download the software. You can get it from here (this site is nothing to do with ours, by the way):
Be sure to click the link for Presentation, as well as the link for Downloads. The Presentation page shows you how to install the file.

What is PHP, and why do I need it?

                PHP is probably the most popular scripting language on the web. It is used to enhance web pages. With PHP, you can do things like create username and password login pages, check details from a form, create forums, picture galleries, surveys, and a whole lot more. If you've come across a web page that ends in PHP, then the author has written some programming code to liven up the plain, old HTML.
                
                PHP is known as a server-sided language. That's because the PHP doesn't get executed on your computer, but on the computer you requested the page from. The results are then handed over to you, and displayed in your browser. Other scripting languages you may have heard of are ASP, Python and Perl. 

               The most popular explanation of just what PHP stands for is "Hypertext Pre-processor". But that would make it HPP, surely? An alternative explanation is that the initials come from the earliest version of the program, which was called Personal Home Page Tools. At least you get the letters "PHP" in the right order!


Cycle of a Normal Web Request


Cycle of a Web Request That Involves PHP

But PHP is so popular that if you're looking for a career in the web design/web scripting industry then you just have to know it!

ASP.Net:CollapsePanelExtender Of Ajax

Friday, 14 September 2012

How To Send Mail From ASP.Net web Application Using C#

Wednesday, 5 September 2012

To See It Clear Run It On FullScreen View In YouTube