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

查看:175
本文介绍了在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的.Properties,SPWeb.RootWeb(用于网站集),SPWeb,SPList等(取决于你需要的范围)使用PropertyBag(键/值对)。

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应用程序的自定义配置选项

作为

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"];

如果您希望UI允许管理员轻松设置值,则可以使用 SharePoint Designer (urghhhh!)或类似于 SharePoint Property Bag Settings

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天全站免登陆