String concatenation problem?

E

Edwin Smith

Hello:

I have a problem building a file command line argument from 2 cells in a
table with the following code.

string filePath =
insuranceDataGridView.CurrentRow.Cells[5].FormattedValue.ToString();
string fileName = "0000000" +
Convert.ToString(Convert.ToDecimal(insuranceDataGridView.CurrentRow.Cells[6].FormattedValue.ToString())
/ 1000) + ".tif";
string cmdArgument = filePath + fileName;

The Path cell in the table = "P:\TTG\Data\VWP\IDCARDS\CD1\"

The string fileName evaluates to "00000004.679.tif" but I'm not having a
problem getting either of these strings.

The problem is when I try to concatenate them together. What I get is
cmdArgument = "P:\TTG\Data\VWP\IDCARDS\CD1\" without the fileName part.

I think it may have something to do with the trailing "\" in the path but
I've tried preceeding the values with a "@" but it doesn't help.

Can anyone show me where I'm going wrong?

Thanks

Edwin
 
P

PokerMan

Well do this:

string filePath = @"P:\TTG\Data\VWP\IDCARDS\CD1\";

string fileName = "00000004.679.tif";

string cmdArgument = filePath + fileName;

Console.WriteLine(cmdArgument);

And you will see it does concat correctly. So i beg to differ in regards to
your comments that filePath and fileName are equal to what you say they are
at the time of the concatenation. So i suggest a console.writeline just
before the concat on both values. See what comes back.
 
L

Laura T.

Just a note.
Whenever constructing paths, it would be good to use Path.Combine() method
to ensure that the path will be good.
 
E

Edwin Smith

You're right!

The table cell was padded with nulls.

PokerMan said:
Well do this:

string filePath = @"P:\TTG\Data\VWP\IDCARDS\CD1\";

string fileName = "00000004.679.tif";

string cmdArgument = filePath + fileName;

Console.WriteLine(cmdArgument);

And you will see it does concat correctly. So i beg to differ in regards
to your comments that filePath and fileName are equal to what you say they
are at the time of the concatenation. So i suggest a console.writeline
just before the concat on both values. See what comes back.




Edwin Smith said:
Hello:

I have a problem building a file command line argument from 2 cells in a
table with the following code.

string filePath =
insuranceDataGridView.CurrentRow.Cells[5].FormattedValue.ToString();
string fileName = "0000000" +
Convert.ToString(Convert.ToDecimal(insuranceDataGridView.CurrentRow.Cells[6].FormattedValue.ToString())
/ 1000) + ".tif";
string cmdArgument = filePath + fileName;

The Path cell in the table = "P:\TTG\Data\VWP\IDCARDS\CD1\"

The string fileName evaluates to "00000004.679.tif" but I'm not having a
problem getting either of these strings.

The problem is when I try to concatenate them together. What I get is
cmdArgument = "P:\TTG\Data\VWP\IDCARDS\CD1\" without the fileName part.

I think it may have something to do with the trailing "\" in the path but
I've tried preceeding the values with a "@" but it doesn't help.

Can anyone show me where I'm going wrong?

Thanks

Edwin
 
E

Edwin Smith

I discovered that the table cell for the filePath was padded with nulls
which was causing the problem. This cleaned it up:

string filePath = filePathCell.TrimEnd('\0');

I also changed the code to use Path.Combine method which seemd the more
elegant way to do it.

Laura T. said:
Just a note.
Whenever constructing paths, it would be good to use Path.Combine() method
to ensure that the path will be good.

Edwin Smith said:
Hello:

I have a problem building a file command line argument from 2 cells in a
table with the following code.

string filePath =
insuranceDataGridView.CurrentRow.Cells[5].FormattedValue.ToString();
string fileName = "0000000" +
Convert.ToString(Convert.ToDecimal(insuranceDataGridView.CurrentRow.Cells[6].FormattedValue.ToString())
/ 1000) + ".tif";
string cmdArgument = filePath + fileName;

The Path cell in the table = "P:\TTG\Data\VWP\IDCARDS\CD1\"

The string fileName evaluates to "00000004.679.tif" but I'm not having a
problem getting either of these strings.

The problem is when I try to concatenate them together. What I get is
cmdArgument = "P:\TTG\Data\VWP\IDCARDS\CD1\" without the fileName part.

I think it may have something to do with the trailing "\" in the path but
I've tried preceeding the values with a "@" but it doesn't help.

Can anyone show me where I'm going wrong?

Thanks

Edwin
 

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