I wanted to create SSRS reports for my SharePoint ASP.NET application. I wanted to make everything about the reports to be a part of a Feature to add.
I will have a Web.Config change to make and RDLC files to copy over to the IIS folder with User permissions set.
Here is what I came up with. On FeatureActivated, I call a function to add the Web.Config settings and then another to copy over the RDLC files.
I created an array of SPWebconfigModifications. You will see a couple I commented out so you can get a better feel for how these settings work. I have three modifications occur. The first adds the HTTPHandler needed for the ReportViewer. The second updates that same record if it already exists. I did this because we had a web.config that had the HTTPHandler already but with version 126.96.36.199. So my add child node did not do anything because it was already there. So the update attribute did the trick. The third change is to add a Remove in the appSettings. There is a setting that is automatically added, but it will error in SharePoint, so I've found the answer out there to be to remove that from the appSettings. The only thing I would want to do to upgrade this is to add code to see if the HTTPHandler is already there or not, then only do the first or second modification but not both.
You will notice I am running in Elevated Privileges mode. You will need this unless your feature is a WebApplication feature. Anything lower will not have permission to change web.config settings.
While copying the files over, I first add a folder if not already present. Didn’t want all those RDLC files sitting in the main folder where the web.config file is. There could be one issue here, which is worrying about the URI length. I did not worry about it in this code, but if you want to add that change, please feel free to post back the changes needed.
This is a great way to add all those web.config settings needed for AJAX, just throw them in the array of SPWebconfigModifications and you will have a Feature that loads/unloads the AJAX web.config settings.