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

}

Disposing SPWeb and SPList(SPObjects)

using (SPWeb web =SPContext.Current.Site.OpenWeb())
{
SPList Projectimages = web.Lists["ProjectPictures"];
SPQuery myQuery = new SPQuery();
SPListItemCollection Items = Projectimages.GetItems(myQuery)
}

If we use Using(){} it will automatically dispose all objects.

We need to declare and use all SPObjects in Using clause

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