When working on big SharePoint projects we will get really good requirements and most of them are the challenging. In some cases we need to show the data by pulling from one list in a site to another site. For example, on “Site A” home page we want to show the data from another site or sub site. Then we need to use the web services and call the list and get the items. This is what this blog post is completely about.
How is it useful?
It is useful because as far as i know we have two ways of doing this without coding.
1. By using IFrames on the web pages. Create a content editor web part on the page of the site where you want to show the list content and add a IFrame and point it to the page where list data is present in another web site. So it is just doing nothing, just loading that page as it is. But it’s not a right way of implementing it. Because if authentication is different then you need to login to the site 2 times. One for the main site and another for the IFrame. Another problem is we can’t use IFrames on the web pages for security and performance issues. So it’s not a good way of doing. Then is there any other way?
2. Yes, We have a solution for this and it’s the better way of implementing it. Call a web services by connecting to the web services of the site we want to get the data, pass credentials and then select the list or library you want. Add a web part to the page and give the list we pulled from web service to the web part. That’s it. It is the easy and efficient way. I am explaining this a little bit detail below.
- Create a SharePoint web part page for showing content by using web services.
- Open the page in SharePoint designer and detach it from page layout.
- Now, we need to add a web part for showing the data. We have a very comfortable and most usable web part in SharePoint nothing but Data View web part. Add this to the page.
- Now, web part is ready and need of data source. So we need to go for list where we have to pull the data. It can be in the current site, sub site or some other site.
- Go to Task pane menu item of SharePoint designer and select the Data Source Library. Now you are able to see the all the data sources exist in the current site only. For example, if you want to pull data from a list which is in subsite or some other site you can’t find the data source entry in the lists and libraries section. This is the time where we need to go for XML web services. See above figure for more details.
- Now we need to add a new XML web service data source to our site. How difficult it will be? very simple, follow below.
- Expand the node XML web services and you can find the link called “Connect to a web service”.
- Now you are open up with a window where you can see the properties of the web service data source.Now we need to set the properties for the data source. Move to the tag General. Fill the name, description and keywords.
- Move to tab source and fill the source description location. You can browse to the location of the site and add the which asmx file you want to add. Or if you know location you can manually enter the url. Usually the location is like this. http://sharepointserver/_vti_bin/lists.asmx?WSDL
- Remember for example purpose, i given the lists.asmx file path, you can use any of available web service.
- Before click on Connect now button, check the credentials. You have options for entering credentials, or use default/windows credentials or don’t ask for credentials etc. Set the credentials type and then say Connect now.
- Now the command to configure. Our case, we want to show the data. So it should be the Select operation.
- Select the port : ListsSoap [default one]
- Select operation type : GetListItems
- Now time to pass parameters to the data source. First thing is you need to select the listname parameter that from which list you need to get the data.You can pass parameters to the web service to filter the results too. For example, if your list has the boolean column for IsUpdated. Then we want to show only the columns which are having IsUpdated=false, then you can set that here. We are done with configuring and setting the data source properties.
- We have data source ready and we need to use it to link to the data view web part.
- If you set everything correct, then you can see the entry under the XML web service section.
- Click on the data source and choose Show data from the menu.
- Now, it will open Data Source Details task pane that pull all the column information from the list that you connected to as shown below.
- Now click on the option “Insert selected fields as” Multiple Item view. It will add all the selected columns to the Dataview web part.
- Save the page and view it in browser.
How nice it is, and how simple it is?
Really thanks to SharePoint designer and Data view web part that makes our work easier.
Please post comments if you have any questions.