2

I tried google, but I did not find answer. Does SharePoint support "global variables" ? Example, if I have site collection and I want to save information "global variable", so I can use it in webpart later?

Or what is best way imitate this? Save information to list?

6

I think what the OP is after is a way to store information that can be made accessible globally. If it is indeed the case, then what can serve this need are property bags. Property bags are a place to store metadata or properties of your SharePoint sites. The Property Bags are implemented as a hash table consisting of property names and values; they can be defined at the following levels:

  • Farm (SPFarm class)
  • Web application (SPWebApplication class)
  • Site collection (SPSite class)
  • Site (SPWeb class)
  • List (SPList class)

This is an example of their usage:

SPFarm farm = SPFarm.Local;
farm.Properties["someKey"] = "someValue";
farm.Update(); //Save changes

For more information, see this excellent blog post:

http://blogs.msdn.com/b/zwsong/archive/2012/03/27/where-should-you-store-your-sharepoint-solution-s-configuration-data.aspx

This codeplex project lets you manage property bags directly from the Central Admin.

0

in sharepoint there is a form of global varibles but not in the sense your talking about! i presume your talking about a class (sharepoint) and within that class you have a global varible. Unfortunatly in sharepoint its not quite like that its more in the sense of using the following:

there are multiple ways to go about this! firstly it depends on how long, what info is stored and who is going to use it.... lets not forget the architecture of your sharepoint setup as that has a vital role todo with speed/time and resources!

for simplicity if its a varible that you want to easily pass through pages than i would use session state / view state varible! it will pass the varible through pages after postback ready for you to use:

How to save variables per user session per page

if you need two webparts to communicate with each other passing values than it would be somthing else! you would connect the two webparts together! so one is a sender and the other is a reciver!

http://msdn.microsoft.com/en-us/library/ms469765%28v=office.14%29.aspx

if you need to sore the info for a period of time over night or days/weeks/months/years than that would be within a list or within the sql server!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.