This article describes file operations.
Here we perform the three operations Delete, Copy & Move File.
First of all is the basic idea of this article..
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
string myFileName = ofd.FileName;
What happens when the above code is used? Using the above code it will open a OpenFileDialog Box & from that the user can select a particular file.
Using the last line it will store the full path of selected file.
See below image:

FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.ShowDialog();
string destpath = fbd.SelectedPath;
Also using the above code it will open a "FolderBrowserDialog" box to select a path. Using the last line it will store the full path of the selected folder.
See the image below:

ofd.Dispose();
fbd.Dispose();
It will release all resources, which were used by "ofd" & "fbd".
ofd.SafeFileName;
It will give only filename with extension instead of full path.
System.IO.File.Delete(myFileName);
It will delete the particular given file from the given path.
System.IO.File.Copy(sourcepath, destpath + "\\" + ofd.SafeFileName);
It will copy the file from the source path to the destination path using the same name & if the name is already at destination path then it will give us a message.
System.IO.File.Move(sourcepath, destpath + "\\" + ofd.SafeFileName);
It will move the file from the source path to the destination path using the same name & if the name is already at destination path then it will give us a message.
Main Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

NassereditedPosted Aug 27, 2011, 2:15 PMEdited Aug 27, 2011, 2:20 PM
thank you alot. it was very helpfull. pls. i have a question: What is function of these codes? and have they relation of (System.Data.SqlClient)?? .............................. btnDeleteFile.Click += new EventHandler(btnDeleteFile_Click); .......... btnCopyFile.Click += new EventHandler(btnCopyFile_Click); ......... btnMoveFile.Click += new EventHandler(btnMoveFile_Click);