How to get full file path from file name?

后端 未结 9 1799
[愿得一人]
[愿得一人] 2021-02-08 16:59

How do I get the full path for a given file?

e.g. I provide:

string filename = @\"test.txt\";

Result should be:

Full Fi         


        
相关标签:
9条回答
  • 2021-02-08 17:59

    try:

    string fileName = @"test.txt";
        string currentDirectory = Directory.GetCurrentDirectory();
        string[] fullFilePath = Directory.GetFiles(currentDirectory, filename, SearchOption.AllDirectories);
    

    it will return full path of all such files in the current directory and its sub directories to string array fullFilePath. If only one file exist it will be in "fullFileName[0]".

    0 讨论(0)
  • 2021-02-08 18:00

    try..

    Server.MapPath(FileUpload1.FileName);
    
    0 讨论(0)
  • 2021-02-08 18:05

    You can get the current path:

    string AssemblyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString();
    

    Good luck!

    0 讨论(0)
提交回复
热议问题