andriscs

Hi,

I'd like to use an application's startup path but when I use Application,StartupPath it gives me a string like "C.\\Programs\\MyDirectory" and an other application couldn't take it (Unrecognizable directory path). I tried to use String.Replace(@"\\",@"\") but the result string is the same. How can I remove the double slashes



Re: Visual C# General How to replace "\" with "\"

Martin Platt

As far as I'm aware you can't. A single "\" means an escape character, so "\\" effectively identifies that the escape character is a "\". .NET automatically performs the conversion for you, but when you use it, for example to find if a folder exists, only the single "\" is searched for.

Perhaps you could be be more specific on the problem, and perhaps some code, and I could try to help

Martin Platt.






Re: Visual C# General How to replace "\" with "\"

boban.s

Can you show your source. C# will show double backslashes in debug if you view variable value, but that is only internaly. If try to use it, or write it in debug window, you will have the string with single backslash.






Re: Visual C# General How to replace "\" with "\"

andriscs

I need the startup directory to pass it to an external program as command line argument.
I know I can split up application startup path along \\ with String.Split() and recombine the pieces with @"\" but I always expect something more - obvious and of course done by someone else earlier Smile

Here is the code, I don't think it would matter:

Code Snippet

Process p=new Process();
string dest=@"DestDir\xyz.txt";
...
p.Arguments=Application.StartUpDirectory+dest;
p.Start()










Re: Visual C# General How to replace "\" with "\"

boban.s

Change this line:
string dest = @"DestDir\xyz.txt";
to
string dest = @"\DestDir\xyz.txt";






Re: Visual C# General How to replace "\" with "\"

Martin Platt

There doesn't appear to be anything wrong with what you're doing there, other than possibly using Path.Combine(Application.StartUpDirectory, dest) to assemble your folder structure correctly.

Does the DestDir folder exist, does the file exist I know I'm asking the obvious here...

Martin Platt.






Re: Visual C# General How to replace "\" with "\"

andriscs

I displayed the path in debug and it was correct with only "\". It seems the destination directoy is causing the problem, the external program can't take it. And I also know why. My program is in my Documents and Setting and when the external program takes the parameters it fails to execute because there is a space in the application path: "extprog.exe C:\Document and Settings\...". And of course it is not allowed to use "C:\Doc..." in the parameter list. I don't like this Tongue Tied