Sometimes as per requirement, we need to add third party DLL’s to our SharePoint solution in order to achieve some functionality that is not available in SharePoint. But in order to use this third party DLL in our application, we sometimes need to follow the below outlined steps.
In order to place the DLL in the bin folder of the sharepoint site, we would have to modify the Trust Level attribute from WSS_Minimal to Full in the web config file of the SharePoint site.
Here is the code snipet to make the above mentioned changes in the web config file programmatically. For this example, I am placing the code snipet in the feature activated event of a Feature present in the solution, having scope of web application.
// Gets the current webapplication from feature properties.
SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
// Declairs the webConfigmodification variable.
SPWebConfigModification myModification = newSPWebConfigModification("level", "configuration/system.web/trust");
//Gets a collection of web config modification.
System.Collections.ObjectModel.Collection<SPWebConfigModification> allModifications = webApp.WebConfigModifications;
myModification.Value = "Full";
myModification.Owner = "OwnerName";
myModification.Sequence = 1;
myModification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute;
allModifications.Add(myModification); // Add the modifications.
webApp.Update(); // Update the Web application.