Sharepoint list items are read through custom WebService

Source: Internet
Author: User

Brief Introduction: it provides integration for other systems and finds that the WebService provided by Sharepoint is not easy to use. Simply write it yourself and use it as a learning record. Of course, the content is relatively simple. I hope you don't mind or scold me. Now, let's go to the topic.

1. First, use vs2008 to create a WebService project, select Asp.net web service application, and enter the project name

2. Add reference

Add Microsoft. sharepoint. DLL file reference, because we need to use the SharePoint object model to read the list information, the DLL file location is C: \ Program Files \ common files \ microsoft shared \ Web Server Extensions \ 12 \ ISAPI \ Microsoft. sharepoint. DLL

3. Add a function

Before the function, write the [webmethod] Mark, and then define the methods, method parameters, and return values we need. In the method, write our calls. My code is a simple example, the return value is of the string type. If the operation fails, the return value is null.

Getlistitem (string weburl, string listname, int ID) // you can call this operation to obtain the list items, including the website address, list name, and ID.

Public String getwebid (string weburl) // obtain the webid attribute of the website

[Webmethod]

Public String getwebid (string weburl)

{

Try

{

Spsite site = new spsite (weburl );

Spweb web = site. openweb ();

Return web. Id. tostring ();

}

Catch (exception ex)

{

Return "";

}

}

[Webmethod]

Public String getlistitem (string weburl, string listname, int ID)

{

Try

{

Spsite site = new spsite (weburl );

Spweb web = site. openweb ();

Splistitem item = web. Lists [listname]. items [ID];

String RT = "title:" + item ["title"]. tostring () + "content:" + item ["content"]. tostring ();

Return RT;

}

Catch (exception ex)

{

Return "";

}

}

4. Test WebService release

After publishing to IIS, open our WebService and we can see that our custom methods are all in WebService.

5. Use two functions

We can test our two functions separately. Click our functions to enter the following interface, enter our parameters, and call them.

6. Call results

If we can see the call results, the first figure below is the getlistitem (string weburl, string listname, int ID) function, and the second figure is the result of getwebid (string weburl.

Summary

Now, my blog record is written here today. We have a lot of comments on the environment to combat the self-confidence I just gave birth!

**************************************** **************************************

Author: Yu

Source: http://www.cnblogs.com/jianyus

The copyright of this article is shared by Yu and the blog Park. You are welcome to reprint it, but please indicate the source.

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.