Overview of the Object Model of the Sharepoint Server-side object model (Part 2)

Source: Internet
Author: User
Tags visual studio 2010

(3) URL

As a B/S system, in SharePoint attributes, method parameters, and return values, a large number of URLs are involved. In general, the URLs involved can be divided into the following four categories:

Absolute path:The complete URL contains the protocol header (HTTP or HTTPS), port number, host name, and so on, for example, http: // myserver/subweb/documents/myfolder/myfile.doc. In Sharepoint, there are not many opportunities to use absolute paths. The attributes of some website-level objects are absolute paths, such as spweb. url and spsite. URL.

Relative server path: The Path starting with "/" relative to the server does not contain the protocol header, port number, and host name, for example,/subweb/documents/myfolder/myfile.doc. In Sharepoint, there are many opportunities to use the relative server path. Some objects contain the serverrelativeurl attribute to describe the relative server path, for example, spfile and spfolder both have such attributes.

Relative website path: It is not a relative path starting with "/" relative to the address of the website. It does not contain the path of the website, for example, documents/myfolder/myfile.doc. In Sharepoint, such paths are also common. Many objects contain the URL attribute, most of which refer to the relative website path (spweb and spsite are exceptions ).

Relative Path: Relative to a specific path, for example, myfolder/myfile.doc (relative to the specified ents path ).

In the attributes, method parameters, and return values of various objects in Sharepoint, as long as the URL is involved, the SDK will clearly specify which URL is the above. In many cases, multiple URLs can be used in method parameters. SharePoint APIs are converted internally.

 

(4) how to try to use and understand the SharePoint Object Model

In the actual development process, the built-in SharePoint Project template in Visual Studio 2010 has helped us make reference to the relevant programming set and namespace, so we don't have to worry about it. However, if we only want to try some objects or determine whether a specific function works normally as we think and want to get results immediately, we can create a console program specifically used to test various object models.

1. Create a console program using the SharePoint Object Model

(1) Start Visual Studio 2010 and select new project );

(2) In the new project dialog box, select console application, and pay attention to the usage.. NET Framework 3.5 is used as the runtime environment (SharePoint 2010 is not used.. Net 4.0 kernel running );

(3) Right-click the project in Solution Explorer, select properties, and on the generate build tab, set "Target Platform target) change to any CPU or x64 (x86 by default, but SharePoint 2010 cannot run in a 32-bit environment );

(4) Select Add reference from the project menu, find Microsoft. SharePoint on the. NET tab, and click OK. Most common server-side object models are included in this Assembly. The Assembly is located in the ISAPI directory in the SharePoint root directory (c: \ Program Files \ common files \ microsoft shared \ Web Server Extensions \ 14, if Visual Studio is not installed on the server, you can also set Microsoft. sharepoint. the DLL file is manually copied and referenced, and does not affect the compilation (but cannot run) of the program ).

[Note] for Sharepoint 2013, the corresponding directory is "15"

(5) Add a namespace in the code. Most common SharePoint object models are included in Microsoft. SharePoint namespaces, and some object models related to server management are included in Microsoft. Sharepoint. Administration namespaces.

Now, we can test our program snippets.

 

2. Why do I use console programs?

Compared with other types of SharePoint project templates, the console program has the following advantages: (1) the environment is simple: the console program runs in an independent process, other code running on the website runs in the IIS process or corresponding user code process, and the console program is not easily affected by other environments. (2) quick result display: Press F5 or Ctrl + F5 to view the running result, without any deployment (although Visual Studio 2010 has simplified the deployment of SharePoint project templates to the extreme ), it does not need to go through the dynamic update and loading process in IIS to run fast. (3) focus only on the functions and logic of data operations, without considering the interface layer.

However, this does not mean that the console program has no disadvantages, one of the limitations is that the Sharepoint Server-side object model-all the content introduced in this chapter-can only run on the Sharepoint Server (the object model accessed by the client is introduced in chapter 5 of this book ), this means that to facilitate writing and debugging, We must install SharePoint and Visual Studio on the same machine (or virtual machine. The second limitation is that the console program is not easy to switch the user identity. when testing the code running results of different users, it is not as convenient as switching users in the browser (although the object model also provides the method of performing operations as a specific user ).

But in general, when we are not sure about the use of a certain method or attribute of an object and need to write some short program fragments for testing, it is a good choice to use the console program. Console programs can also be used as unit testing tools for some simple modules. In fact, I often use console programs to test the use of some unfamiliar object models or to test the running results of some code snippets when writing the actual project code.

Therefore, all the code snippets in this chapter are demonstrated through the console program created in the above process.

 

3. How to quickly view common objects and their attributes on a website

Before Visual Studio 2010, when we develop some SharePoint projects or applications, the most troublesome thing is to frequently switch from Visual Studio to a browser, to view the website's hierarchy, the list name, and various attributes of the field, it is even more troublesome, some attributes are hard to be found on the page during development (for example, internal names of fields ). Now, by using the new SharePoint connections feature in Visual Studio 2010, we can quickly learn the structure of websites and lists in Visual Studio, even the specific attributes of these common objects.

In the Server Explorer window in Visual Studio, we will see a "SharePoint connections" node. We can right-click it, select Add connection to add the SharePoint site we need. Then, through this node, we can see all the sub-sites, lists, list columns, content types, workflow templates, and other common objects on the website. After selecting an object, in the Properties window of Visual Studio, you can immediately see all the properties of the selected object. With the support of this built-in tool, the development efficiency of Sharepoint is greatly improved.

Overview of the Object Model of the Sharepoint Server-side object model (Part 2)

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.