Msdn visual series: use tokens in wssv3 to get the listid and Itemid for the custom application page

Source: Internet
Author: User
Original article: http://msdn2.microsoft.com/en-us/library/bb418733.aspx

The previous article introduced "Create a feature extended Sharepoint list item or an operation menu item for the document ". You can navigate to the custom application page in this way. Taking project-level review as an example, we can add a menu item to each document in a document library and navigate to a custom application page to display the review history of the document.

When a user clicks a menu entry on a list item, an application page is usually run. The code behind this page is usually programmed for the list item or document you clicked earlier. To achieve this effect, the application page must be able to obtain the list item or document. SharePoint adds the list item or document identity information to the query string on the application page to pass this information. In this way, the page can obtain the information through code during its initialization and create the splistitem object and the splist object to which it belongs.
We compile the customaction object to create a menu item on the list entry and navigate the user to the custom page. In this process, we can use dynamic tags (tokens) to configure URL attributes. SharePoint will replace these tags at runtime. Generally, we set the URL attribute of the urlaction element to something similar to the following :~ Site/_ layouts/itemaudit. aspx? Itemid = {Itemid} & amp; listid = {listid}

This URL directs the user to a custom page named itemaudit. aspx. We noticed that the URL contains three tags. ~ The site is replaced by the URL of the current website. The {listid} part is replaced by the guid of the current list or document library. The {Itemid} part is replaced by the ID number of the current list item or document. The latter two are often used to create a query string to pass information to the application page so that it can locate entries in the list or document library objects.

Now, we can use the code to obtain the list item ID passed by the query string and Its guid. Use the querystring attribute of the standard ASP. NET Request object to receive the request. Spsite sitecollection = This. Site;
Spweb site = This. Web;
// Obtain query string values
String listid = request. querystring ["listid"];
String Itemid = request. querystring ["Itemid"];
// Create list object and list item object
Splist list = site. Lists [New GUID (listid)];
Splistitem item = List. Items. getitembyid (convert. toint32 (Itemid ));
// Query for information about list and list item
String listtitle = List. title;
String itemtitle = item. title;

What is important here is whether the spdocumentlibrary object or splist object is used for code? The document library is a special list. We can convert the splist object to the spdocumentlibrary object. Through conversion, we can use more attributes and methods that are only valid for the document library. You can also use the File Attribute of splistitem to return a spfile object. In this way, we can program to access the document itself.

If (list is spdocumentlibrary ){
Spdocumentlibrary documentlibrary = (spdocumentlibrary) List;
String documenttemplateurl = documentlibrary. documenttemplateurl;
Spfile file = item. file;
String fileauthor = file. Author. Name;
String filesize = file. totallength. tostring ("0, ###") + "bits ";
}

View Video

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.