Sharepoint 2010 Answers

 
Home » Forum » Sharepoint 2010       Ask a questionRSS Feeds
  Question Asked By: Shradha Shrestha   on Aug 13, 2010 In Sharepoint 2010 Category.

 
Question Answered By: Shradha Shrestha   on Aug 13, 2010

Jordon,

This is how I did:
if (pubPage != null  && pubPage.Layout.Title == "Home page  Layout")
{

//Get the list
SPList HomepageImage = currentWeb.Lists["Homepage Images"];

//Create a query
SPQuery query = new SPQuery();
query.Query = string.Format("<Where><And><Gt><FieldRef Name='ID' /><Value Type='Counter'>0</Value></Gt><Leq><FieldRef Name='ID' /><Value Type='Counter'>4</Value></Leq></And></Where>");

//Get the list  items
SPListItemCollection collListItems = HomepageImage.GetItems(query);

//Select one of the list items randomly  
 random  random = new Random();
int i = random.Next(1, 4);
 string  sUrl = "";

foreach (SPListItem Listitem in collListItems)
{

if (Listitem["ID"].ToString().CompareTo(i.ToString()) == 0)
{


Microsoft.SharePoint.Publishing.Fields.ImageFieldValue h = (Microsoft.SharePoint.Publishing.Fields.ImageFieldValue)Listitem["Image"];
testImage.ImageUrl = h.ImageUrl;

break;
}


testImage.ImageUrl = sUrl;

}

}

Tagged:                

 

This Question has 5 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Display Publishing Image to the page from a SPList Or get search suggestion and latest updates.