SharePoint 2010: Setting SafeControl "SafeAgainstScript" property on web part installation

2.3k views Asked by At

Is there any way to set the SafeAgainstScript property of the SafeControl entry in the Web.config file to true upon installation / upgrade of the web part? (it always defaults to false)

The SafeControl entry should appear as follows:

<SafeControl Assembly="Microsoft.SharePoint, ..." Namespace="Microsoft.SharePoint" TypeName="*" Safe="True" SafeAgainstScript="True" />

I am installing a third party web part and would like NOT to have to go back and edit the config file each time the web part is re-installed or upgraded.

1

There are 1 answers

0
int32 On BEST ANSWER

Well i guess theres no "easy" way to do it.

You can edit the web.config using the SPWebConfigurationModification class http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebconfigmodification.aspx

http://msdn.microsoft.com/en-us/library/bb861909.aspx

However, this can be very tricky and is not recommendeded - The SafeControl entries are meant to put in manually or using the .wsp's manifest.xml file

So you basically would open the .wsp with WinRar or 7zip, extract the manifest.xml, make the change to the Safecontrol entry and reassemble it back together and then deploy it.

If you really want to automate this process, you can do so using http://msdn.microsoft.com/en-us/library/system.io.packaging I'm sure you will find some code snippets about this aswell