I placed a WCF service in IIS, and when I work, when I call its methods, I want the data to be written to a text file. How to place a path on a PC in a hosted WCF, where should I create and save a text file?
1 answer
In Web.config in the configuration section in the appSettings section appSettings add a key and value for it as follows:
<configuration> <appSettings> <!-- Путь к файлу --> <add key="myFile" value="C:\myFile.txt" /> </appSettings> </configuration> Further in the code, using the ConfigurationManager class, ConfigurationManager key and read the value:
var filePath = ConfigurationManager.AppSettings["myFile"]; // вернет C:\myFile.txt PS In order for the ConfigurationManager class to be available, the System.Configuration.dll library must be connected.
|
appSettingssectionappSettingsdeclare the required key, in which the value is the path to the file. - sp7