From an ASP.NET MVC app I am trying to concatenate two paths, a remote server path with a path extracted from database. I am performing below:
string serverPath = @"\\myServer\TempFolder";
string filePath = GetPathFromDatabaseTable();
string finalPath = System.IO.Path.Combine(serverPath, filePath);
GetPathFromDatabaseTable method returns this string:
\\path\\to\\file.pdf
When concatenating using Path.Combine, the result got into finalPath is:
\\path\\to\\file.pdf
So the prefix serverPath \myServer\TempFolder is removed. Why is happening?
Dropping the leading slash at the beginning from filePath works as explained here in the solution.
so if in database is stored as \path\to\file.pdf then when I read from database I drop the leading slash at the beggining, so GetPathFromDatabaseTable method returns:
instead of:
so then when combining using System.IO.Path.Combine it works perfectly.