Wednesday, December 22, 2010

Getting ImageLink from sharepoint PictureLibrary and displaying in imagecontrol

using (SPWeb web =SPContext.Current.Site.OpenWeb())
{
SPList Projectimages = web.Lists["ProjectPictures"];
SPQuery myQuery = new SPQuery(); //CAML Query to get only images based on WbsId
myQuery.Query = string.Format("" + strWBSId + "");
// Get a collection of Items based on Query
SPListItemCollection Items = Projectimages.GetItems(myQuery);
if (Items.Count > 0)
{
foreach (SPListItem item in Items)
{
imgProjectImage.ImageUrl = string.Concat(web.Url, "/", item.Url.ToString());
imgProjectImage.Attributes.Add("style", "display:block"); //By default image display property was hidden,when the image is there in library then only we are dispalying that image
break;
}
}

}

No comments:

Post a Comment

Content Editor Webpart not showing up in SharePoint Online ------------------------------------------------------------------------------...