File.Copy \r \n prepended and appended Question

N

needin4mation

Hi,

foreach (ListViewItem item in listViewFiles.Items)
{
MessageBox.Show(item.SubItems[0].Text + ", " + item.SubItems[1].Text);
string source=item.SubItems[0].Text;
string destination=item.SubItems[1].Text;
File.Copy(source,destination,true);
item.SubItems[2].Text="Success";
}

In this snippet, when I retrieve the text from the listview it looks
fine in the MessageBox. It looks exactly like my xmlFile that holds
the data. I had a MessageBox on the strings there too and it looked
fine.

However, when I run it I get an error about the path not being right.
I put a breakpoint on the File.Copy method and when I hover over the
variables source and destination, it has this:

\r\nC:\mysource\r\n
\r\nC:\mydest\r\n

Where did the extra \r\n come from? How do I get rid of them? Thank
for any help.
 
G

gmiley

string source = item.SubItems[0].Text.Trim();
string destination = item.SubItems[1].Text.Trim();


That should work for you, it removes any whitespace from the beginning
and ending of a string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top