SharePoint Study Notes-10 ways to access ingress poin configuration information

Source: Internet
Author: User
Tags configuration settings

how to save configuration information is an inevitable problem for sharepiont application development. Here we list 10 ways in which they have different application environments and advantages and disadvantages.
1. Use the APP/Web config file
SharePoint-related web. the Config File package is contained in the following folders in the file system:

    • /inetpub/wwwroot/WSS/virtualdirectories/port number-defines the Web configuration settings for the SharePoint content web application Program . config file.
    • /inetpub/wwwroot/WSS/virtualdirectories/Management Center Port Number-defines the Web. config file for the SharePoint Management Center application.
    • /inetpub/wwwroot/WSS/virtualdirectories/port number \ wpresources-the Web. config file used in the Web Part resources of the Web application.
    • // Program/files \ common files \ microsoft shared \ Web Server Extensions \ wpresources-the web. config file used in the Web Part resources cached by the global assembly.
    • % ProgramFiles % \ common files \ microsoft shared \ Web Server Extensions \ 14 \ config-define the web for extending the configuration settings of other web applications. config File and other. config file.
    • % ProgramFiles % \ common files \ microsoft shared \ Web Server Extensions \ 14 \ ISAPI-defines the web. config file for the/_ vti_bin virtual directory.
    • % ProgramFiles % \ common files \ microsoft shared \ Web Server Extensions \ 14 \ template \ layouts-defines the web. config file for the/_ layouts virtual directory.

When creating a Sharepoint Foundation web application. the config file is located in the content root folder of the Web application, which defines configuration settings for the server (for example, HTTP processing for Web parts ).

Another web. config file used for Web Part resources is located in the \ wpresources folder in the same root folder.
You can program to modify some of the preceding webconfig files (such as spwebconfigmodification class using Microsoft. Sharepoint. Administration namespaces ).

The Web. config method is applicable to scenarios where the configuration information needs to be effective within the scope of the Web-application, but the application is a little heavy.

2. Use Sharepoint list
Some people use creating data tables in the database to access configuration information. This is not a good method, but it is not a good method in SharePoint solution development. You can use a Sharepoint list instead of a database table. Because it is relatively simple, the created Sharepoint list can contain two data columns: Title and value, in this way, you can save the configuration information to this list. The advantage of using this method is that you do not need to develop another user management interface to manage your configuration information, because in Sharepoint, these are automatically available with the list, you only need to set the relevant permission on this list (because not everyone can view and modify it ). Of course, this is also insufficient, that is, you need additional configuration information to tell you where to look for such a list, it seems that it has come back again.

 

3. Use splist. rootfolder. Properties
If you want to access the configuration information associated with the list, you can use splist. rootfolder. properties.

// Get value
Splist. rootfolder. properties [ " Vti_listservertemplate " ] = Myvalue
// Set Value
String Myvalue = splist. rootfolder. properties [ " Vti_listservertemplate " ]

 

4. Use Web part Storage
We can use a format similar to [personalizable (personalizationscope. Shared), webpartstorage (storage. Shared)] Public String title {} to access configuration information related to Web parts.

# Region Webpart Properties
[Webbrowsable ( True ),
Category ( " Facebook settings " ),
Personalizable (personalizationscope. Shared ),
Webpartstorage (storage. Shared ),
Defaultvalue ( "" ),
Webdisplayname ( " User ID/User Name " ),
Webdescription ( " Please enter user ID " )]

Public string userid { Get ; set ;}

[webbrowsable ( true ),
category ( " Facebook Settings " ),
personalizable (personalizationscope. shared),
webpartstorage (storage. shared),
defaultvalue ( " 10 " ),
webdisplayname (" wall count " ),
webdescription (" Please enter number of wall you want to display " )]

Public IntWallcount {Get;Set;}

# Endregion

5. Use spweb object
Spweb object has a persistent stringdictionary attribute named properties, which can be used to save specific configuration information related to the site, and this configuration can be effective throughout your farm. You can use the followingCodeTo operate on it:

Spweb = ...;
// Set the value
Web. properties [ " Thesetting " ] = " The Value " ;
// Update the value
Web. properties. Update ();
// Get the value
String Val = web. properties [ " Thesetting " ];

 
Therefore, this method is very effective for saving configuration information in the key/value format, and it is not convenient to save complicated configuration information, you need to store the sequences of relatively complex configuration information into XML mode and serialize/deserialize (serialization/deseralization ). Of course, you need to obtain the manged web permission to perform these operations. In addition, you need to develop your own user operation interface to manage the configuration information.

 

6. Use spsite object
Unlike spweb object, spsite object does not have the same properties as spweb object properties. Therefore, if you want to access site collection-level configuration information, you can use spsite. rootweb is a special spweb object.
 
7. Use spwebapplication Properties
If you want to access configuration information at the web application level, but you do not want to modify web. config, you can use spwebapplication object. The spwebapplication object is inherited from the sppersisted object. It also has a hashtable attribute named properties. You can use it to access configuration information in the key/value format, complicated information can also be processed through serialization. The sample code is as follows:

Spwebapplication webapp =...
Object OBJ =...
// Set Value
Webapp. Add ( " Thesetting " , OBJ );
// Persist it
Webapp. Update ();

This method requires you to perform operations with the farm administrator permission and you need to build your own operation management interface.

 

 8. Use custom sppersistedobjects
Maybe custom sppersistedobjects is the best way to access the configuration information of Web applications. The advantage of this method is that it is more convenient to access complicated configuration information, you can create a class that inherits from sppersistedobject, set the configurations to be accessed to attributes of this class, and mark these attributes as persisted. The sample code is as follows:

Public Class Thesettings: sppersistedobject { Public Thesettings (){}
Public Thesettings ( String Name, sppersistedobject parent, guid ID ): Base (Name, parent, ID ){}
[Persisted] site. rootweb. rootfolder. properties. Add ("sitename", "yoursite ");
Public String Webserviceurl;
}

Then you can use the spwebapplication getchild method to extract the configuration information you saved above.

Thesetasksettigs = webapplication
. Getchild <thesettings> ( " Thesettings " );

You can create two static methods to facilitate your operations. Of course, this method still requires farm administrator and you need to create your own management interface.

Public Static Thesetaskgetsettings (spwebapplication webapplication) {thesetasksettings = webapplication. getchild <thesetask> ( " Thesettings " ); If (Settings = Null ){ Return Thesettings. createnew (webapplication );} Return Settings ;} Public Static Thesetaskcreatenew (spwebapplication webapplication ){ Return New Thesettings ( " Thesettings " , Webapplication, guid. newguid ());}

9. Use the XML file in feature folder
You can save the configuration information to an XML file and place it under the corresponding feature folder. This mode features that the configuration information does not depend on SharePoint, in addition, users are generally not allowed to directly modify (that is, static configuration information is stored ).

10. A config store framework
You can get this framework (SharePoint config store). This framework allows you to save configuration information to the list and provide APIs to extract your saved configuration information, these configuration information can be complex objects, which are saved in XML format.

Here we will list 10 ways to access configuration information in SharePoint solution development. The sample code is just a reference. You need to check the specific technical text to use the relevant content, the application code is not important because it only scans the access configuration information.

I believe you have used other methods. Please write them out and share them with you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.