Click here to Skip to main content
15,910,603 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi Everybody
i have a problem so please help me
i have a one .txt file in C drive and it's name is Hello.txt
now i want to copy this file to D drive. using C# window application

thanks in Advance
Posted
Updated 10-Mar-10 0:35am
v2

Firstly, don't title your question "Hi Everybody" - it tells us nothing about what your problem is. Use "How to copy a file?" or similar.

Use File.Copy[^]
 
Share this answer
 
Hi kikhatri, the below is the code to copy the file one location to another. Hope this would help you.

private void button1_Click(object sender, EventArgs e)
{
StreamReader objReader = new StreamReader("C:\\Hello.txt");
string sLine =string.Empty;
ArrayList arrText = new ArrayList();
while (objReader.Peek() == 72)
{
sLine = objReader.ReadLine();
if (sLine != "")
arrText.Add(sLine);
}
FileInfo fi = new FileInfo("D:\\Hello.txt");
// Actually create the file.
FileStream fs = fi.Create();
Byte[] fb =
new UTF8Encoding(true).GetBytes(arrText.ToString());
fs.Write(fb, 0, fb.Length);
// Modify the file as required, and then close the file.
fs.Close();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900