2012-02-01 92 views
0

在開發環境IIS託管WCF訪問文件

string AppPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); 
       string path = AppPath + "\\options.xml"; 

作品。

當由生產IIS7服務器託管時,我把Options.xml放在bin環境中,但上述代碼生成的路徑是一個asp.net temp目錄。 那麼在開發和生產環境中訪問文件的正確技術是什麼? 感謝

回答

0

這是信息使用的是支持你的服務? 如果是這樣,是否有任何理由,你不能只是做一個自定義的配置類,並從您的web.config節讀取它?

+0

聽起來像一個優雅的解決方案。充其量,我對Web.config的使用是最基本的。我會做一些挖掘。作爲利益的問題解決了即時問題與字符串path = System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly()。GetName()。CodeBase)+「\\ options.xml」; – 2012-02-02 18:22:57

0

您可以使用此:

string path = System.IO.Directory.GetCurrentDirectory();