none
Lookup field + Img url

    Question

  • Hi All,

    I have Images,Pages library & have a lookup field in the pages library to Images Library Title field.

    Now I want programmatically to fetch Images url of Images Library when I connected to Pages Library lookup field.

    Any help would be appreciated.

    Let me know if you have any queires.

    Thanks & Regards,
    SPUser.
    Friday, September 06, 2013 8:38 AM

Answers

  • Hi,

    According to your description, you want to get image URL through lookup field.

    The code snippet below for your reference:

    using (SPSite spSite = new SPSite("http://sharepoint2010/"))
    {
        using(SPWeb spWeb=spSite.OpenWeb())
        {
                       
            SPList pageList=spWeb.Lists["PageLibrary"];
            SPList imageList=spWeb.Lists["ImageLibrary"];
                       
            foreach (SPItem item in pageList.Items)
            {
    
                SPFieldLookupValue group = new SPFieldLookupValue(item["ImageTitle"].ToString());
                SPItem lookupItem = imageList.GetItemById(group.LookupId);
                string imageUrl=lookupItem["ImageURL"].ToString();
            }
        }            
    }
    
    Best Regards

    Dennis Guo
    TechNet Community Support

    • Marked as answer by spuser2013 Thursday, September 12, 2013 6:55 AM
    Monday, September 09, 2013 11:42 AM
    Moderator

All replies

  • Hi,

    According to your description, you want to get image URL through lookup field.

    The code snippet below for your reference:

    using (SPSite spSite = new SPSite("http://sharepoint2010/"))
    {
        using(SPWeb spWeb=spSite.OpenWeb())
        {
                       
            SPList pageList=spWeb.Lists["PageLibrary"];
            SPList imageList=spWeb.Lists["ImageLibrary"];
                       
            foreach (SPItem item in pageList.Items)
            {
    
                SPFieldLookupValue group = new SPFieldLookupValue(item["ImageTitle"].ToString());
                SPItem lookupItem = imageList.GetItemById(group.LookupId);
                string imageUrl=lookupItem["ImageURL"].ToString();
            }
        }            
    }
    
    Best Regards

    Dennis Guo
    TechNet Community Support

    • Marked as answer by spuser2013 Thursday, September 12, 2013 6:55 AM
    Monday, September 09, 2013 11:42 AM
    Moderator
  • Hi Dennis,

    Thanks a lot for your response. Is it possible to get the Image Url without connecting to the Images Library(without using SPList imageList=spWeb.Lists["ImageLibrary"];)

    Could you suggest any alternate way for the same!

    Let me know if you need more information.

    Thanks In Advance,
    SPUser.
    Wednesday, September 11, 2013 12:20 PM
  • Hi,

    Per my knowledge, we can not get the Image Url without connecting to the Images Library.

    More information:

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

    Best Regards


    Dennis Guo
    TechNet Community Support

    Thursday, September 12, 2013 1:23 AM
    Moderator