2011-09-17 62 views

回答

6

花了一点挖,但我发现在最后的答案。您可以通过使用以下代码获取Javascript中列表的Id:

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

一起传递也很有意义,谢谢分享! –

0

你会发现,在SPContext类

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

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

要分析你可以使用这样的事情

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 

C#的网址

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; 
    } 
} 

好运

+0

感谢您的回复,但我需要使用Javascript来完成此操作。真的很抱歉没有在我原来的帖子中清楚地说明这一点! –

+0

嗯,更好的办法是有一个代码隐藏页面提供JavaScript。如果你想用js做一些事情,用var url = window.location; var urlparts = url.split('/'); –

+0

我不认为这是可能的。我的自定义操作JavaScript正在为我的应用程序页面构建查询字符串,然后通过SP模式对话框打开它。我不认为后面的应用程序页面代码将能够使用SPContext访问列表名称,因为它不在列表页面上?将列表名与查询字符串 –

相关问题