Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Site Property Management (SharePoint 2010)

, 11 Jul 2010 CPOL
Provides an administrative UI to manage custom properties for a SharePoint site
SPFSiteProperty.zip
QuestechSystems.SiteProperty
AppGlobalResources
SharePointProjectItem.spdata
bin
Release
QuestechSiteProperty.wsp
QuestechSystems.SharePoint.ApplicationPages.SiteProperty.dll
QuestechSystems.SharePoint.ApplicationPages.SiteProperty.pdb
ElementManifests
SharePointProjectItem.spdata
Features
QuestechSiteProperty
QuestechSiteProperty.feature
Layouts
Questech
SharePointProjectItem.spdata
Package
Package.package
pkg
pkgobj
Release
TokenReplaceFolder
Layouts
Questech
QuestechSiteProperty
ElementManifests
Release
QuestechSiteProperty
Layouts
Questech
QuestechSiteProperty
ElementManifests
Resources
QuestechSystems.SharePoint.ApplicationPages.SiteProperty.dll
Properties
QuestechSystems.SiteProperty.csproj.user
//
//	EditSiteProperty.cs - © Questech Systems
//	This notice must stay intact for use. Not for resale.
//
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.ApplicationPages;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebControls;

namespace QuestechSystems.SharePoint.ApplicationPages
{
    public partial class EditSiteProperty : WebAdminPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                string propertyName = base.Request.QueryString[Utility.QueryKeyParamProperty];
                if (this.Web.GetProperty(propertyName) == null)
                {
                    throw new SPException(AppGlobalResources.QuestechSiteProperty.MsgSitePropertyNotFound);
                }

                if (!(this.Web.GetProperty(propertyName) is String))
                {
                    OKButton.Enabled = false;
                }

                string propertyValue = this.Web.GetProperty(propertyName).ToString();
                this.NameInputFormTextBox.Text = propertyName;
                this.ValueInputFormTextBox.Text = propertyValue;
            }
        }

        protected void OKButton_Click(object sender, EventArgs e)
        {
            if (!this.Page.IsValid)
            {
                return;
            }

            string originalProperty = base.Request.QueryString[Utility.QueryKeyParamProperty];
            string propertyName = this.NameInputFormTextBox.Text.Trim();
            string propertyValue = this.ValueInputFormTextBox.Text.Trim();

            if (String.IsNullOrEmpty(propertyName))
            {
                NameErrorLabel.Text = AppGlobalResources.QuestechSiteProperty.MsgSitePropertyNameEmpty;
                return;
            }

            try
            {
                if (this.Web.GetProperty(propertyName) == null)
                {
                    this.Web.DeleteProperty(originalProperty);
                    this.Web.AddProperty(propertyName, propertyValue);
                    this.Web.Update();
                }
                else
                {
                    if (propertyName == originalProperty)
                    {
                        this.Web.SetProperty(propertyName, propertyValue);
                        this.Web.Update();
                    }
                    else
                    {
                        NameErrorLabel.Text = AppGlobalResources.QuestechSiteProperty.MsgSitePropertyExists;
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new SPException(ex.Message);
            }

            if (SPContext.Current.IsPopUI)
            {
                Utility.ModalDialogClose(AppGlobalResources.QuestechSiteProperty.MsgSitePropertyUpdated);
            }
            else
            {
                SPUtility.Redirect(Utility.PageNameManageSiteProperties, SPRedirectFlags.UseSource, this.Context);
            }            
        }

        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            if (!this.Page.IsValid)
            {
                return;
            }

            string propertyName = this.NameInputFormTextBox.Text;
            if (this.Web.GetProperty(propertyName) != null)
            {
                try
                {
                    this.Web.DeleteProperty(propertyName);
                    this.Web.Update();
                }
                catch (Exception ex)
                {
                    throw new SPException(ex.Message);
                }
            }

            if (SPContext.Current.IsPopUI)
            {
                Utility.ModalDialogClose(AppGlobalResources.QuestechSiteProperty.MsgSitePropertyDeleted);
            }
            else
            {
                SPUtility.Redirect(Utility.PageNameManageSiteProperties, SPRedirectFlags.UseSource, this.Context);
            }      
        }

        protected override bool RequireSiteAdministrator
        {
            get
            {
                return true;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Stephen Huen
Software Developer (Senior)
Canada Canada
A Microsoft Certified Professional Developer and Technology Specialist.
 
Experience and expertise in SharePoint 2013 / 2010 / 2007.
 
Role ranges from a developer in a multi-person team to a solution consultant with expert-level skills, leading a project to completion status.
 
Proven experience working effectively in a team environment and a self-managed environment.
Follow on   LinkedIn

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150123.1 | Last Updated 12 Jul 2010
Article Copyright 2010 by Stephen Huen
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid