During the creation of Sharepoint, we may have created multiple sharepoint primary websites, and each primary website has some subwebsites, so how can I display the list of other primary websites and subwebsites on my own page?
We encountered this problem during the development of this project. At present, I have summarized two implementation methods:
I. How to connect to other libraries using data view
This method is relatively simple, but it can only share the list between the current primary website and its own sub-websites, if you want to share the list of Sharepoint sites on other primary websites or even on other machines, use the second method.
Use Cases: At that time, there was a portal website under the project, which included the news subsystem and blog subsystem. The articles in these subsystems should be displayed on the homepage of the portal.
Usage:
1. Open Sharepoint Designer, select task pane> data source library from the menu, and open the view of the data source library.
2. Click "connect to other libraries..." at the bottom of the data source library, and enter the path of other Sharepoint sites in the pop-up window.
Then, the list of the website is displayed in the view of the data source database.
3. Insert a data view into your own page
4. Select the list to be displayed in the data source database View> display data
5. Select the expected field from the data source Details View and insert it to the data view.
6. After insertion, you can control the display format in the normal data view mode.
With the above operations, you can share the view of the sub-website on any page.
2. Customize your own data view and implement your own webpart by inheriting DataFormWebPart
This method is relatively complicated, but it is powerful and controllable and can implement many complex functions.
Use Cases: We use the tfs 2008 system. Every time a project is created in tfs, A sharepoint website is automatically generated (http: // ***: 88/sites/Projectname) To save project documents and other information on this website, we want to create a unified website where documents of different projects are dynamically displayed based on input parameters.
Usage:
Through multiple experiments, I found that DataFormWebPart is a bit equivalent. NET, you can obtain your own data source when binding the data source to display the list of other websites. The Code is as follows: 1 // custom data view, display different project documents based on different projects
2 public class MyDataFormWebPart: DataFormWebPart
3 {
4 private string _ tfsUrl = "http: // server: 88/sites /";
5 [WebBrowsable (true), Personalizable (true)]
6 public string TfsUrl
7 {
8 get {return _ tfsUrl ;}
9 set {_ tfsUrl = value ;}
10}
11
12 private string _ docName = "Project Management ";
13 [WebBrowsable (true), Personalizable (true)]
14 public string DocName
15 {
16 get {return _ docName ;}
17 set {_ docName = value ;}
18}
19
20 public override void DataBind ()
21 {
22 string ProjectName = Page. Session ["SESSION_PROJECT_NAME"] as string;
23 SPSite site = new SPSite (TfsUrl + ProjectName );
24 SPWeb web = site. AllWebs [0];
25 SPList list = web. Lists [DocName];
26
27 (this. DataSource as SPDataSource). List = list;
28
29 base. DataBind ();
30}
31
32}
The key is the 23-27 lines of code, which dynamically determines which list to bind to based on the input parameters.
With this webpart, we can use it on our own page. The usage method is not as good as that of the standard data view control. Pay attention to the following problem:
After binding to the document library, you can correctly display the document under this document, but it cannot be opened because the original document path is: http: // server: 88/sites/library/DocLib2/Project%20Checklist.xls, the url path of the document will be spelled as http: // server: 999/sites/library/DocLib2/Project%20Checklist.xls after it is displayed on other websites, because the value of the @ FileRef field stored in the database is a relative path
Solution: Add a parameter to the data view.
Then replace all @ FileRef with concat ($ DocHomeUrl, @ FileRef), so that you can view and download it correctly.
(PS: When parameters are added, Sharepoint Desinger automatically deletes a parameter in SelectParameters:
<Asp: QueryStringParameter QueryStringField = "RootFolder" Name = "RootFolder" Type = "String"> </asp: QueryStringParameter>
If deleted, manually add
Sharepoint Desinger often deletes some code by mistake, and often reports errors. Now we do not dare to design the view during development, but dare to develop it in the Code view.
)
The above only enables viewing and downloading documents. If you want to add, delete, or perform other operations, the basic idea is similar to the solution for viewing, of course, the implementation may be more complicated.