how to access SharePoint web config Programmatically |
In SharePoint 2010, you can easily access SharePoint's Web.Config file using SPWebConfigModification class of the Microsoft.SharePoint. It can be used in the situations where you might need to write an assembly to SafeControls element in your web config file using object model or may be something else.Well, the cool thing is these modifications are written to the web.config files on every front-end web server when the SPWebService. Below is an example shows how to use the SPWebConfigModification class to register a custom assembly. SPWebService service = SPWebService.ContentService; SPWebConfigModification myModification = new SPWebConfigModification(); myModification.Path = "configuration/SharePoint/ myModification.Name = "SafeControl[@Assembly=' myModification.Sequence = 0; myModification.Owner = "User Name"; myModification.Type = SPWebConfigModification. myModification.Value = ""; service. /*Call Update and ApplyWebConfigModifications to save changes*/ service.Update(); service. Calling the ApplyWebConfigModifications method schedules a timer job to deploy the changes throughout the server farm. To apply a web.config modification to a specific Web application, add the modification to the collection of web.config modifications for the Web application (WebConfigModifications). For example, you can use oWebSite.Site.WebApplication. |
Monday, November 28, 2011
how to access SharePoint web config Programmatically
Category:
SharePoint 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment