Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am working on a Custom Action that I want to add to all list instances as well as all user groups. The purpose is to export the list / group as a document to allow the user to export it when Client Integration is not enabled (it's a FBA site). I have the following XML in my elements.xml file:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
  GroupId = "ActionsMenu"
  Location="Microsoft.SharePoint.StandardMenu"
  ImageUrl="/_layouts/images/MenuSpreadsheet.gif"
  Sequence="1000"
  Title="Export to Excel">
    <UrlAction Url="~site/_layouts/LetGuide/ExportToExcel.aspx?ListId={ListId}"/>
  </CustomAction>
  <CustomAction
  GroupId = "ActionsMenu"
  Location="Microsoft.SharePoint.PeoplePage"
  ImageUrl="/_layouts/images/MenuSpreadsheet.gif"
  Sequence="1000"
  Title="Export to Excel">
    <UrlAction Url="~site/_layouts/LetGuide/ExportToExcel.aspx?ListId={ListId}"/>
  </CustomAction>
</Elements>

My question is: On the receiving ASPX page, is the list ID enough for me to pull out the specific SPList instance (this might be on the root web or a sub-web - the feature is deployed at site scope)? And will it work for user groups as-is? (I am not sure if they have list IDs in the same manner as normal lists).

If anyone can point me to some sample code or documentation for how a receiving ASPX page could be created, that would be a great help.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

Actually, all you need is to read intently the following MSDN topic:

You can see now, that besides of {ListId} token, you can also use the {SiteUrl} token, which will point to the URL of the current web:

{SiteUrl} - URL of the Web site (SPWeb).

And SPWeb object can be retrieved easily by its url, using SPSite.OpenWeb(url) method.

But actually you can even do without this token.

Since you're specifying ~site token, the ExportToExcel page will be initialized with the context of the current web.

~site - Web site (SPWeb) relative link.

So, you will be able to use SPContext.Current.Web or just this.Web to get the SPWeb object, where the list is stored.

And once you've got the SPWeb object, you can grab the list using SPWeb.Lists[Guid] indexer.

The code of the Page_Load method will look something like this:

public void Page_Load()
{
    var listGuid = new Guid(Request.Params["ListId"]);
    var list = this.Web.Lists[listGuid];
    // do whatever you need with the list
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.