.Net provides an API in the System.IO.Path Class. The Combine method of this class serves as solution to all such problems.
This has very simple straight-forward syntax:
COMBINE ( System.String path1 , System.String path2 )
The good thing about this method is that, the second parameter can be an absolute
path or only the filename.
For e.g.: If you have a file “Tip.txt” in “C:\\Test” directory.
You could use this function as:
strFilePath = System.IO.Path.Combine("C:\\ Test", Tip.txt);
OR
strFilePath = System.IO.Path.Combine("C:\\ Test\\", Tip.txt);
OR
strFilePath = System.IO.Path.Combine("C:\\ Test", “C:\\Test\\Tip.txt”);
All of them yield the same result. And the problem of trailing slash is removed.