This article will show you how you can copy file from one
directory to other directory in windows application using c#.net.
Some of my previous articles are as follows: Blinking
Text in C#.Net Windows Application, Focus
on TextBox in C#.Net in Windows Application, Limit
OR Restrict Number of Characters in Textbox C#.Net In windows Application, AutoSuggest
DropDownList In Windows Application Using C#.Net, Random
Character and String Generation Using C#.Net, Windows Application and Linq,
Strong
Random String Password Generation Using C#.Net.
so for this article we will create a new windows application and add the below code .
Now check the directory
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;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void button1_Click(object
sender, EventArgs e)
{
try
{
string
fileName = "TestFile.txt";
string
sourcePath = textBox1.Text;
string
targetPath = textBox2.Text;
//Combine
file and path
string
sourceFile = System.IO.Path.Combine(sourcePath,
fileName);
string
destFile = System.IO.Path.Combine(targetPath,
fileName);
//Copy
file from source to targett
System.IO.File.Copy(sourceFile, destFile, true);
MessageBox.Show("Copy done successfully.");
}
catch
(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
}
}
|
Now we have done run the application and check the output.
0 comments:
Please let me know your view