Forum Discussion
pratiksavla
Oct 09, 2023Copper Contributor
SharePoint (2019) PowerShell Command for SPSite.WebApplication.Properties
We are trying to set and get properties in WebApplication using following code SPSite site = new SPSite(<SiteUrl>)
// or
SPSite site = SPFeatureReceiverProperties.Feature.Parent as SPSite
// set pr...
pratiksavla
Oct 10, 2023Copper Contributor
Hi LeonPavesic
We have already used the SPSite.WebApplication.Properties as mentioned in the original post with Add/Remove functions. But we are unable to get the values set by powershell commands in C# code..
LeonPavesic
Oct 10, 2023Silver Contributor
Hi pratiksavla,
To ensure that the properties are available in your C# code, you may need to perform an IISRESET (Internet Information Services Reset) on the SharePoint server after setting the properties using PowerShell. This will refresh the server and clear any caches, making the properties available to your C# code.
Here's how you can perform an IISRESET:
Open Command Prompt or PowerShell with administrator privileges on the SharePoint server.
Run the following command to perform an IISRESET:
iisreset /noforce
This will restart IIS and refresh the SharePoint server.
After performing the IISRESET, try accessing the properties in your C# code using SPSite.WebApplication.Properties again. The values set via PowerShell should now be available.
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.
If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
(LinkedIn)
- pratiksavlaOct 10, 2023Copper Contributor
Hi LeonPavesic
We tried performing IISReset but it did not solve the issue.
Although using following code we were able to set the property via powershell and get the property in C# code:
$site = GetSPSite '<siteurl>' $site.WebApplication.Properties.Add('Property1','Value1') $site.WebApplication.Update() $site.dispose()
But now when the property is set or updated using C# code we are not able to see the changes in powershell.