Timer jobs are recurring background processes which will automatically run at particular time.
In my recent project i have written a timer job which will read the data from SQL table and process the same. Generally we will store the connection strings in web.config file. Timer jobs will run under the OWSTimer process, so there is no direct way to interact with web.config file. The workaround is we will use the webconfigurationmanager class.
Please find the below code snippet for complete understanding.
public override void Execute(Guid contentDbId) { try { string config = WebConfigurationManager.OpenWebConfiguration("/", this.WebApplication.Name); SPWebApplication webApp = this.Parent as SPWebApplication; string url = webApp.AlternateUrls[0].Uri.ToString(); string Host = config.AppSettings.Settings["Static_Email_SMTP_Host"].Value.ToString().Trim(); } catch (Exception ex) { ErrorLog(ex.Message, "ExitLetter EmailNotification-Execute()", this.GetType().Name); } }
No comments:
Post a Comment