WebSettings.Lookup C# (CSharp) Method

Lookup() public method

Get a setting as a string value; throw an exception if its not found
public Lookup ( string key ) : string
key string key
return string
	public string Lookup(string key)
	{
		XmlNode setting = settingsXML.SelectSingleNode( "/settings/setting[@key='" + key + "']" );
		return setting.ChildNodes[0].Value;
	}

Same methods

WebSettings::Lookup ( string key, string defaultValue ) : string

Usage Example

Ejemplo n.º 1
0
	/// <summary>
	/// Append a line to the applicable log file
	/// </summary>
	/// <param name="logEntry">line to add to log</param>
	public void LogAppend(string logEntry)
	{
		// use the timestamp captured when the object was created to identify the file
		string fname = LogFilename(timestamp);
		WebSettings ws = new WebSettings();

		// create a full path to the target log file
		string logpath = ws.Lookup("LogPath", HttpContext.Current.Server.MapPath("~/App_Data"));
		logpath = Path.Combine(logpath, fname);

		// append to the log file or create it if it doesn't exist
		if (!File.Exists(logpath))
		{
			using (StreamWriter sw = File.CreateText(logpath))
			{
				sw.WriteLine(logEntry);
			}
		}
		else
		{
			using (StreamWriter sw = File.AppendText(logpath))
			{
				sw.WriteLine(logEntry);
			}
		}
	}
All Usage Examples Of WebSettings::Lookup