Patrick Kun Patrick Kun -3 years ago 107
C# Question

Transfer a textfile to another folder

I am quite confused as to why my code isn't working. I wanted to transfer a textfile that I have into another folder. Here is my code:

private void transferButton_Click(object sender, EventArgs e)
{
string acct = @"C:\\Users\\Accounting\\TicketQueue\\";
string reg = @"C:\\Users\\Registrar\\TicketQueue\\";

if (office == "Registrar")
{
File.Move(reg, acct);
}
else {
File.Move(acct, reg);
}

cleanUp();
}


The office variable is determined beforehand. (Registrar or Accounting)

The cleanup() method is used to clear the entire form and prompt a message that successfully transfers the file.

Everytime I click the button an error displays saying:

Additional information: Could not find file 'C:\Users\Accounting\TicketQueue\'.

Answer Source

You have not actually specified a file name, just a folder location. Do you know the name of the file, or are you trying to transfer the entire folder's contents? Code would need to be something like:

string acct = @"C:\\Users\\Accounting\\TicketQueue\\from.txt";
string reg = @"C:\\Users\\Registrar\\TicketQueue\\to.txt";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download