Best Practices in SharePoint development (continued)

Source: Internet
Author: User
Tags connectionstrings

Best Practices in SharePoint Development

20. Introduction to spviewscope

Default: Only files and subfolders in the specified folder are displayed.

Filesonly: Only files in the specified folder are displayed.

Recursive: displays files in all folders.

Recursiveall: displays all files and subfolders in all folders.

The preceding attributes are used in caml to control the scope of searches. We can set the viewattribute attribute based on actual search requirements to complete our operations.

21. Introduction to spgridview

Based on the gridview, spgridview has made some extensions, that is to say, it has all the functions of the gridview and has been improved accordingly. The improved functions include grouping, paging, drop-down menu, and filter. However, spgridview does not support automatic column generation. Therefore, you must set the autogeneratecolums attribute to false when using it.

22. Introduction to the replace method of JavaScript

Use the replace method of javescript. This method supports regular expressions. If no regular expression is used, the first matching character is replaced by default. Therefore, we use STRM. Replace (/&/g, "//") to separate all target characters in the string. Therefore, using this method with the corresponding regular expression is very powerful.

23. Use spfolder folder = web. getfolder (URL );

In this way, the folder object is directly obtained through the URL without passing through the list level, and the list data may not be initialized. Therefore, the folder. parentlistid may be empty, so that the list object cannot be obtained. That is to say, the attributes of the parent list object corresponding to this folder object cannot be obtained.

24. when we update some objects in the Web, although we call the web. update () method, but the API in SharePoint does not reload the web object, that is, it does not reload some new metadata from the database to the web object, in this way, object inconsistency may occur. The solution to this problem is to obtain the web object again when we use the web.

25. when using the checkout and checkin methods, you must first determine the state of the file to be operated. If it is not checkout, it cannot be checkin. If it is checkout, it cannot be checkout again. At the same time, the file checkout is equivalent to adding a lock to the file to identify the File status. If this file is checkout, other people cannot checkout it unless they force the discard checkout.

26. note the usage of the allowunsafeupdate attribute. This attribute is used to prevent unsafe updates. If we want to update some objects on the web, if this attribute is not set to true, a verification exception occurs. If the object httpcontext. Current is null, this attribute will always be true. When using this attribute, make sure that the web object we want to update is set. If not, an exception will occur during the update, in the past, we performed some operations on the web, so that the web object changes. This is no longer the current web object, that is, the object inconsistency, so we need to re-obtain this web object and then set this property.

27. generally, when deploying Sharepoint, we use WSP to deploy some files and update the web. config. config adds some custom nodes and may modify the original nodes. Therefore, WSP cannot fully meet our needs. We should use the webconfigurationmodification class for the web. modify the config file. As follows:

Using (spsite sitecollection = new spsite ("http: // CHRIS: 11111/sites/testconfig "))

{

Using (spweb site = sitecollection. openweb ())

{

Site. allowunsafeupdates = true;

Spwebapplication APP = sitecollection. webapplication;

Spwebconfigmodification modification1 = new spwebconfigmodification ();

Modification1.path = "configuration ";

Modification1.name = "connectionstrings ";

Modification1.value = "<connectionstrings> </connectionstrings> ";

Modification1.owner = assembly. getexecutingassembly (). fullname;

Modification1.sequence = 100;

Modification1.type

= Spwebconfigmodification. spwebconfigmodificationtype. ensuresection;

App. webconfigmodifications. Add (modification1 );

Spwebservice service = spfarm. Local. Services. getvalue <spwebservice>

();

Service. applywebconfigmodifications ();

}

}


Best Practices in SharePoint development (continued)

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.