2014-10-08 49 views
0

我想寫一個測試來檢查我的應用程序中的一些設置配置文件存在。獲取解決方案中的所有應用程序和Web配置文件

我將如何去解決所有的應用程序/網絡配置文件的解決方案?

+0

做ü意味着「如何訪問一個特定的目錄的文件?」 – 2014-10-08 12:18:50

+0

我想編寫一個測試,以確保我的解決方案中的應用程序配置文件都不包含特定的設置。如果我將另一個項目添加到解決方案並且它不包含該配置,這應該會失敗 – TJF 2014-10-08 12:21:07

回答

1

通過使用目錄搜索,你可以得到的文件

string[] configFiles = Directory.GetFiles(@"YourSolutonDirectoryLocation", "*.config", SearchOption.AllDirectories) 
           .Where(x => x.EndsWith("App.config") || x.EndsWith("Web.config")).ToArray(); 
1

據我理解您的文章, 請使用以下獲得all filesdirectory

public string[] GetAllFilesInDirectory(string path, string startsWith, string fileExt) 
    { 
     string[] filenames = Directory.GetFiles(path, startsWith + "*" + fileExt); 
     return filenames; 

    } 

用法:

string[] arr= GetAllFilesInDirectory(somepath,startswith,".config"); 

希望這有助於!

相關問題