-1

Hi I have an issue with Path.Combine that it does not return the corect result. Here is what I mean.I ave to combine 4 strings into a bath:

string basePath = "D:\\Programare\\Visual Studio\\TFS Workspace\\CodeArt\\Development\\CodeArt\\Backend\\WebApi\\CodeArt.WebApi\\bin\\..\\Content\\"
string userId = "4d52ec77-966a-480a-a4c3-c1ff67438fe9";
string filePath = "\\Avatar";
string storageFileName = "ffdc24a9-f553-41ce-aa33-042b07fcfdab.png";

var result  = Path.Combine(basePath , userId , filePath , storageFileName);

Now for some reason my this code returns only "\Avatar\ffdc24a9-f553-41ce-aa33-042b07fcfdab.png".

Am I doing something wrong why am aint Path.Combine concatantes all the string.

aleczandru
  • 5,319
  • 15
  • 62
  • 112

1 Answers1

6

From MSDN: Path.Combine(String, String, String, String)

path1 should be an absolute path (for example, "d:\archives" or "\archives\public").If one of the subsequent paths is also an absolute path, the combine operation discards all previously combined paths and resets to that absolute path.

Asper the MSDN documentation Path1 should be an Absolute Path and you should not have Absolute Path in any subsequent paths

Replace This:

string filePath = "\\Avatar";

With This:

string filePath = "Avatar";
Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67