locked
Fetching the url of the listitem from the id RRS feed

  • Question

  • Hi,

    How to get the list item url from the Id of the document?

    I am getting the ID of the list item in the querystring from the below c# code.

    [CODE]

     string ids = Request.QueryString["ID"].ToString();

    [/CODE]

    Is it possible to get the url of the listitem(document url) from the id?

    Thank you

    Tuesday, May 15, 2012 6:15 AM

Answers

  • Hi

    JPRoelofse's suggestion will give you the correct item. To read the url you need to add the following line at the end:

    string url = item.URL;


    Regards Bjoern
    Blog

    • Marked as answer by Venkatzeus Wednesday, May 23, 2012 4:41 AM
    Tuesday, May 15, 2012 6:50 AM
  • Hi,

    This follwing code will give you the entire list item.

    Its properties will contain all the URL's you need

    //ids = your query string value
    
    int iSessionID = 0;
    int.TryParse(ids, out iSessionID);
    
    SPListItem item = web.Lists[ListName].GetItemById(iSessionID);

    Regards,

    JP

    • Proposed as answer by Bjoern H Rapp Tuesday, May 15, 2012 6:50 AM
    • Marked as answer by Venkatzeus Wednesday, May 23, 2012 4:41 AM
    Tuesday, May 15, 2012 6:44 AM

All replies

  • Hi,

    This follwing code will give you the entire list item.

    Its properties will contain all the URL's you need

    //ids = your query string value
    
    int iSessionID = 0;
    int.TryParse(ids, out iSessionID);
    
    SPListItem item = web.Lists[ListName].GetItemById(iSessionID);

    Regards,

    JP

    • Proposed as answer by Bjoern H Rapp Tuesday, May 15, 2012 6:50 AM
    • Marked as answer by Venkatzeus Wednesday, May 23, 2012 4:41 AM
    Tuesday, May 15, 2012 6:44 AM
  • Hi

    JPRoelofse's suggestion will give you the correct item. To read the url you need to add the following line at the end:

    string url = item.URL;


    Regards Bjoern
    Blog

    • Marked as answer by Venkatzeus Wednesday, May 23, 2012 4:41 AM
    Tuesday, May 15, 2012 6:50 AM
  • Hi,

    The listname is dynamic one.so how to add the ListName?

    I only have the document id.

    Tuesday, May 15, 2012 7:22 AM
  • Hi,

    You need the list name or list id, if you want to get the list item.

    Where are you getting the list item id to send to the query string? from another page?

    if so, either put that into the query string aswell or create a session and store it in the session.

    Regards,

    JP

    Tuesday, May 15, 2012 7:32 AM