1
Reply

Custom webpart to display list of all pages from a wiki lib

Atif Rahim

Atif Rahim

Dec 11 2017 1:02 AM
150

Hi I am creating a cusotm webpart in SharePoint 2013 to display the name of all the wiki pages library on the home page so that when user click on any link it will open the wiki page.

I have done this before in SharePoint 2010 to read the list items but the same thing I am trying to do in SharePoint 2013 not able to get any result.

below if my code.
  1. void loadData()  
  2. {  
  3. SPSecurity.RunWithElevatedPrivileges(delegate()  
  4. {  
  5. try  
  6. {  
  7. // using (SPWeb mySite = SPContext.Current.Site.AllWebs["/"])  
  8. using (SPSite site = new SPSite(SPContext.Current.Web.Url))  
  9. {  
  10. using (SPWeb Web = site.RootWeb)  
  11. {  
  12. SPList list = Web.Lists["PeopleNews"];  
  13. SPQuery query = new SPQuery();  
  14. query.RowLimit = 5;  
  15. query.Query = "";  
  16. //Synergies and growth  
  17. SPListItemCollection items = list.GetItems(query);  
  18. string strPR = string.Empty;  
  19. if (items.Count > 0)  
  20. {  
  21. foreach (SPListItem item in items)  
  22. {  
  23. string strTitle = (item[linkTitle] == null ? "--" : (item[linkTitle].ToString()));  
  24. strPR += "" + strTitle + "";  
  25. }  
  26. }  
  27. PR.Text = strPR;  
  28. }  
  29. }  
  30. }  
  31. catch (Exception ex)  
  32. {  
  33. }  
  34. });  
I just want to show the top 5 pages link from the wiki page library on the home page.
 
Thanks  

Upload Source Code  Select only zip and rar file.
Answers (1)