在 SharePoint 站点中存储站点级全局变量的正确方法是什么? [英] What is a proper way to store site-level global variables in a SharePoint site?

查看:23
本文介绍了在 SharePoint 站点中存储站点级全局变量的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我对 SharePoint2007 感到抓狂的一件事是明显无法具有专门应用于网站或网站集本身而不是内容的可定义设置.我的意思是,您有一些预定义的设置,例如站点徽标、站点名称和其他各种内容,但似乎没有任何地方可以添加新的设置.

One thing that has driven me nuts about SharePoint2007 is the apparent inability to have defineable settings that apply specifically to a site or site collection itself, and not the content. I mean, you have some pre-defined settings like the Site Logo, the Site Name, and various other things, but there doesn't appear to be anywhere to add new kinds of settings.

我正在开发的应用程序需要能够创建多种类型的项目网站集",它们都遵循一个基本模板,但具有特定于该网站集且仅适用于该网站集的某些附加设置.除了标准站点名称之外,我们还需要定义项目编号、项目名称和客户名称.考虑到我们一些客户的要求,我们还需要进行可配置的设置来改变某些工作流程的工作方式,例如文件是用字母还是数字标记.

The application I am working on needs to be able to create multiple kinds of "project site collections" that all follow a basic template, but have certain additional settings that apply specifically to that site collection and that one alone. In addition to the standard site name we also need to define the Project Number, the Project Name, and the Client Name. And given the requests of some of our clients, we also reach a point where we have to have configurable settings that alter how some of the workflows work, like whether files are marked with Letters or Numbers.

我们目前的解决方案是将 XML 文件存储在 SharePoint 服务器上,我对此犹豫不决.此文件包含每个网站集的一个节点,由根网站的 URL 标识.节点内是需要为该网站集定义的所有元素.当我们需要它们时,我们每次都必须访问 XML 文件(它总是需要 SPSecurity.RunWithElevatedPrivileges 才能访问服务器上的文件)来加载它并检索数据.有很多自动化流程必须执行此操作,当我们访问数百个站点,其中包含运行数万个工作流的数千个文件,所有站点都想访问此文件时,我对这种方法的稳定性感到犹豫.也许他们是毫无根据的担忧,但我宁愿担心也不愿冒几年后一切都会破裂的风险.

Our current solution, which I'm hesitant about, has been to store an XML file on the SharePoint server. This file contains one node for each site collection, identified by the URL of the root site. Inside the node are all of the elements that need to be defined for that site collection. When we need them, we have to access the XML file (which will always require SPSecurity.RunWithElevatedPrivileges to access files right on the server) every time to load it and retrieve the data. There are a lot of automated processes which will have to do this, and I'm hesitant about the stability of this method when we reach hundreds of sites with thousands of files running tens of thousands of workflows, all wanting to access this file. Maybe they're unfounded worries, but I'd rather worry than risk everything breaking in a couple years.

我正在查看 SPWeb 对象并找到了 AllProperties 哈希表.看起来只是那种可能有用的东西,但我不知道修改它有多安全.我通读了 MSDN 和 WSS SDK,但没有发现任何关于将全新属性添加到 AllProperties 的说明.将 AllProperties 用于这种事情是否安全?或者我还缺少另一个可以处理网站集或网站范围内的全局变量概念的功能吗?

I was looking into the SPWeb object and found the AllProperties hashtable. It looks like just the kind of thing which might work, but I don't know how safe it is to be modifying this. I read through both MSDN and the WSS SDK but found nothing that clarified on adding completely new properties into AllProperties. Is it safe to use AllProperties for this kind of thing? Or is there yet another feature that I am missing, which could handle the concept of global variables at the site collection or site scope?

推荐答案

推荐的方法是通过 SPFarm、SPWeb.RootWeb(用于网站集)、SPWeb 的 .Properties 使用 PropertyBag(键/值对)、SPList 等(取决于您需要的范围).

The recommended way to do this is to use PropertyBag (key/value pairs) through the .Properties of SPFarm, SPWeb.RootWeb (for site collections), SPWeb, SPList etc (depending upon the scope that you need).

MSDN - 管理 SharePoint 的自定义配置选项申请

有一个生产就绪代码可作为

There is a production ready code available as part of the

MSDN - SharePoint 指南库

请参阅分层配置管理器

这使您可以通过编程访问读取/写入这些值.如果您想在不使用指南库的情况下执行此操作,则可以使用类似于以下代码的内容.

This gives you programmatic access to read/write these values. If you want to do this without using the guidance library then you would use something like the following code.

SPWeb web = SPContext.Current.Web;
if (web.Properties.ContainsKey("MyProperty"))
   string myProperty = web.Properties["MyProperty"];

如果您希望用户界面允许管理员轻松设置值,请使用 SharePoint Designer (urghhhh!) 或类似 SharePoint 属性包设置

If you want a UI to allow admins to easily set the values then use either SharePoint Designer (urghhhh!) or something like SharePoint Property Bag Settings

这篇关于在 SharePoint 站点中存储站点级全局变量的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆