c# - How to get relative path of file which is in project folder? -


i tried using @"~\testdata\test.xml", trying file bin/debug instead of project folder.

you can achieve getting parent of current directory, using directory class in system.io namespace. see code example.

using system.io;  namespace consoleapplication15 {     class program     {         static void main(string[] args)         {             var projectfolder = directory.getparent(directory.getcurrentdirectory()).parent.fullname;             var file = path.combine(projectfolder, @"testdata\test.xml");         }     } } 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -