Reputation: 18127
I have the code below and I get the result like this
C:\\Users\\Administrator\\Projects\\CA\\Libraries\\ConvertApi-DotNet\\Example\\word2pdf-console\\bin\\Release\\\\..\\..\\..\\..\\test-files\\test.docx
The file is found but I would like to show user this path and the formating is not user friendly. I would like to get
C:\\Users\\Administrator\\Projects\\CA\\Libraries\\test-files\\test.docx
I have tried to use Path.Combine but it do not work.
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string inFile = baseDirectory + @"\..\..\..\..\test-files\test.docx";
Upvotes: 1
Views: 227
Reputation: 60556
You say that the file is found.
Then you can use FileInfo (namespace System.IO)
for that.
FileInfo f = new FileInfo(fileName);
f.Exists // Gets a value indicating whether a file exists.
f.DirectoryName // Gets a string representing the directory's full path.
f.FullName // Gets the full path of the directory or file.
Upvotes: 3
Reputation: 64148
You could use a combination of Path.Combine
and Path.GetFullPath
:
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
var file = @"..\..\..\..\test-files\test.docx";
string inFile = Path.GetFullPath(Path.Combine(baseDirectory, file));
Upvotes: 3