Reputation: 2192
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?
Upvotes: 9
Views: 2649
Reputation: 1096
Remove the initial backslash from "\EADBScripts..." in the second argument.
Upvotes: 2
Reputation: 1472
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.
Upvotes: 16
Reputation: 94653
string targetPath = @"C:\Program Files\saadhvi\SetupSafetyPADUniversal\";
string createDatabasesScriptFilePath;
createDatabasesScriptFilePath= Path.Combine(targetPath, "EADBScripts\\CreateDatabases.sql");
Upvotes: 1
Reputation: 2815
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 \.
Upvotes: 11