Path problem

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

Hello,

i try to write some data into an XML-file via c#. When I specify the
path like "c:\\temp\\test.xml" the XmlTextWrite could open the file.
But when I tried to get the path from Directory.GetCurrentDirectory()
and combine it with
my file, the XmlTextWriter couldn't open the file.

The returned path from Directory.Get... contains only one \. Is this
the problem?
Does anybody know how to receive the path with two \\? Or is it my
task to scan the string an insert the missing \? I don't think so!

Hope anybody can help.

Thanks!
Tim
 
All paths use just single backshlash to separate directories. The difference
you see is just in the C# string literal. You can either use:

@"C:\dir1\dir2\dir3"

OR

"C:\\dir1\\dir2\\dir3"

The debugger watch window displays information in one of these formats, the
one it considers better.

And to combine paths, it's best to use Path.Combine(). Or, in the case you
want to get a path relative to current directory, you can use
Path.GetFullPath() as well.

HTH,
Stefan
 
Hello,

thanks a lot for your help. I've found my error.
I combine the 2 paths via Directory.GetCurrentDirectory() and an
Treeviewnode, DBTree.SelectedNode.FullPath, where my
DBTree.PathSeparator = "\\". The Treeview displays my Database. The
error was, than the db is in another directory called "Parts". Now I add
the "Parts" to the .GetCurrent...() and it works fine ;-)

Today is not my day ...

Thanks again,
Tim
 
Hi,

Nop, it's ok
you have to do something like this

string filename = Directory.GetCurrentDirectory() + "\\" + filename;

cheers,
 
Back
Top