SharePoint SharePoint Client Object Model - Get the name of the current list

I am trying to create a simple custom action button for a feed menu in Sharepoint 2010.

I want to keep it universal, so there is no hard coding of library names, etc.

How to find out the name of the currently viewed list? I would suggest that this is possible without having to parse it with Url.

Many thanks!

+6
source share
2 answers

It took a little digging, but I found the answer at the end. You can get the list id in Javascript using:

//Get the Id of the list var listId = SP.ListOperation.Selection.getSelectedList(); 
+7
source

You will find that in the SPContext class

 SPList list = SPContext.Current.List; string listTitle = list.Title; 

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spcontext.aspx

To parse the url you can use something like this

Vb.net

 Private Function TryGetListName() As String If String.IsNullOrEmpty(Me.ListName) Then Dim path() As String = Me.Page.Request.Url.AbsolutePath.Trim("/"c).Split("/"c) Dim listName As String = String.Empty For i As Integer = 0 To path.Length - 1 If path(i).ToLower = "lists" Then If i < path.Length - 1 Then listName = path(i + 1) End If Exit For End If Next Return listName Else Return Me.ListName End If End Function 

FROM#

 private string TryGetListName() { if (string.IsNullOrEmpty(this.ListName)) { string[] path = this.Page.Request.Url.AbsolutePath.Trim('/').Split('/'); string listName = string.Empty; for (int i = 0; i <= path.Length - 1; i++) { if (path[i].ToLower() == "lists") { if (i < path.Length - 1) { listName = path[i + 1]; } break; } } return listName; } else { return this.ListName; } } 

Good luck.

0
source

Source: https://habr.com/ru/post/897548/


All Articles