Read file name from File path provided RRS feed

  • Question

  • User1810310269 posted



      I need to read the file name from the path provided.I am passing the filepath from config file, now i need to append the CSV file name present at that location.

    Please find code for reference below.

    //I am hard coding the value of file name.
    string csv_file_path = ConfigurationSettings.AppSettings["SecondaryInstance"].ToString()+"\\test.csv";
    //Config file path
    <add key="SecondaryInstance" value="C:\\Anand\\Rbac\\Sync Test\\Destination\\"/>


    i am expeting that my "csv_file_path" varaible should have full path with file name(Not hard coded).





    Thursday, August 7, 2014 3:06 AM


  • User-809753952 posted
    string csv_file_folder = ConfigurationSettings.AppSettings["SecondaryInstance"].ToString()
    var csv_files = new DirectoryInfo(csv_file_folder).GetFiles("*.csv");
    var csv_file_name = csv_files[0].Name;  //I assume there is only one csv file
    string csv_file_path = csv_file_folder  + "\\" + csv_file_name ;

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 7, 2014 4:06 AM