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?

  • Add to the WCF configuration file the path to the file to which you are going to write. Next, from the config, read the path to the file, and write to it. - sp7
  • @ sp7, WCF configuration file is Web.config? - lcnw
  • Yes, in the appSettings section appSettings declare the required key, in which the value is the path to the file. - sp7

1 answer 1

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.