9
    string targetPath = @"C:\Program Files\saadhvi\SetupSafetyPADUniversal\";
    string createDatabasesScriptFilePath = Path.Combine(targetPath, "\\EADBScripts\\CreateDatabases.sql");

i am getting the value of createDatabasesScriptFilePath is \EADBScripts\CreateDatabases.sql

but i expected it would be C:\Program Files\saadhvi\SetupSafetyPADUniversal\EADBScripts\CreateDatabases.sql

what is the wrong with my code?

4 Answers 4

16

Here is why your code is returning the 2nd path (copied from MSDN help) -

If path2 does not include a root (for example, if path2 does not start with a separator character or a drive specification), the result is a concatenation of the two paths, with an intervening separator character. If path2 includes a root, path2 is returned.

Sign up to request clarification or add additional context in comments.

Comments

11

Remove the first \ from the string "\EADBScripts\CreateDatabases.sql"

I'm not completely sure of the reason, but a I guess Path.Combine wants as second parameter a relative path, and a relative Path does not start with a \.

Comments

2

Remove the initial backslash from "\EADBScripts..." in the second argument.

Comments

1
string targetPath = @"C:\Program Files\saadhvi\SetupSafetyPADUniversal\"; 
string createDatabasesScriptFilePath;
createDatabasesScriptFilePath= Path.Combine(targetPath, "EADBScripts\\CreateDatabases.sql");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.