Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3943438
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:46:55+00:00 2026-05-20T00:46:55+00:00

I have custom List which has image field. I have to display the image

  • 0

I have custom List which has image field. I have to display the image through the object modelling code.

Which Control I need to use to display the image in a webpart and which property I need to assign it for.

[Guid("207cea76-b1ee-4b86-9638-00c22d3d9398")]
public class News : System.Web.UI.WebControls.WebParts.WebPart
{
    Label lblTitle;
    ImageField  imgNews;
    Label lblDescription;
    public News()
    {
    }

    protected override void CreateChildControls()
    {
        base.CreateChildControls();
        lblTitle = new Label();
        imgNews = new ImageField();
        lblDescription = new Label();

        string siteURL = "http://my-dev-box-har";
        using (SPSite site = new SPSite(siteURL))
        {
            using (SPWeb web = site.OpenWeb())
            {
                SPListItemCollection  list = web.Lists["News"].Items ;
                foreach (SPListItem  item in list)
                {
                    lblTitle.Text = item["Title"].ToString();
                    lblDescription.Text = item["Description"].ToString();
                    imgNews. = item[""].ToString();
                    Controls.Add(lblTitle);
                    Controls.Add(lblDescription);
                   }




            }
        }

    }
}

}

I don’t know wheather to use image or Imagefield control to display my image form the sharepoint custom list.

Could anybody point me in right direction please.

Thank you
Hari

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:46:56+00:00Added an answer on May 20, 2026 at 12:46 am

    This is the most simple example I could come up with:

    using System.ComponentModel;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Microsoft.SharePoint;
    
    namespace TestPictureWebPart.PicWebPart
    {
        [ToolboxItemAttribute(false)]
        public class PicWebPart : WebPart
        {
            protected override void CreateChildControls()
            {
                SPList list = SPContext.Current.Web.Lists["ImageList"];
                SPListItemCollection items = list.Items;
    
                foreach (SPListItem item in items)
                {
                    string title = item[SPBuiltInFieldId.Title].ToString(); // or string title = item.Title;
                    SPFieldUrlValue picture = new SPFieldUrlValue(item["MyPicture"].ToString());
    
                    Image image = new Image();
                    image.ToolTip = title;
                    image.ImageUrl = picture.Url;
                    Controls.Add(image);
                }
            }
        }
    }
    

    Just a tip: it’s always better to use SPBuiltInFieldId to access out-of-the-box columns in SharePoint.

    Also, in your example code… if you have more than one listitem in your list, you are in trouble. You will use the same web controls (the labels for example) for each listitem and add them to the Controls collection in every iteration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below code, which iterates over a list based on a custom
I have a custom list, and I've added a 'Page Image' field by clicking
I have a custom content type which has a field called location which is
I have a SharePoint list, which has attachments!! I am using a custom grid-view
I have a List of custom object, which consist of a custom list. class
I have a list of div's in my code which have a custom data-attribute
I have a custom object type which has to be editable in PropertyGrid :
I have a strongly typed list of custom objects, MyObject , which has a
I have a custom list_display field which is responsible for a column of integers
I have a custom list in SharePoint (specifically, MOSS 2007.) One field is a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.