Sharepoint 图像自定义网页部件

Sharepoint 图像自定义网页部件,sharepoint,Sharepoint,我有一个自定义列表,其中有图像字段。我必须通过对象建模代码显示图像 我需要使用哪个控件在Web部件中显示图像,以及需要为哪个属性分配图像 [Guid("207cea76-b1ee-4b86-9638-00c22d3d9398")] public class News : System.Web.UI.WebControls.WebParts.WebPart { Label lblTitle; ImageField imgNews; Label lblDescription

我有一个自定义列表,其中有图像字段。我必须通过对象建模代码显示图像

我需要使用哪个控件在Web部件中显示图像,以及需要为哪个属性分配图像

[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);
                   }




            }
        }

    }
}
}

我不知道是使用image还是Imagefield控件在sharepoint自定义列表中显示我的图像

谁能给我指一下正确的方向吗

多谢各位
哈里这是我能想到的最简单的例子:

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);
            }
        }
    }
}
提示:在SharePoint中使用SPBuiltInFieldId访问开箱即用列总是更好的

另外,在您的示例代码中。。。如果列表中有多个listitem,则会遇到麻烦。您将为每个listitem使用相同的web控件(例如标签),并在每次迭代中将它们添加到控件集合中