Reza on blogging [MVP]

THIS BLOG HAS MOVED TO: http://blogs.devhorizon.com/reza

Subscriptions

<January 2009>
SuMoTuWeThFrSa
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

News



toronto.sharepoint.camp


Navigation

Post Categories

Other Bloggers

Personal Links

Monday, November 21, 2005 - Posts

Retrieving random images from picture library in sharepoint

If you are planning to create a web part that can retrieve and display a thumbnail of a random image from the picture library, then you have two options:

1) The images are stored as binary fields in the DOCS table inside the _SITE database. The field name is CONTENT. Simply connect to the database to retrieve the image. This is not the way I usually get stuff done in SPS.

2) I would suggest you access the images via the Sharepoint namespaces. Picture libraries store their image files in the same manner as document libraries store documents, so get a reference to the picture library as an SPList class and retrieve the image from the SPListItem.File property.

 

protected override void RenderWebPart(HtmlTextWriter output)
{
   string url;
   string caption;

   string HTMLtext;
    try
      {
         SPWeb mysite=SPControl.GetContextWeb(Context);
         SPListCollection lists=mysite.Lists;
         foreach (SPList list in lists)
            {
            if (list.Title.Equals(PicLib.ToString()))
                  {
                  SPListItemCollection items=list.Items;
                  int rndCount=items.Count;
                  if (rndCount > 0)
                     {
                         int intRandom=rIndex.Next(1,rndCount);
                         url= items[intRandom].File.Url;
                         caption=items[intRandom].File.Title;
                         HTMLtext= "some html text";

                         output.Write(HTMLtext);
                     }
                  else
                    {
                  output.Write("There is no picture in the selected picture library.");
                    }
              }
          }
      }
catch(Exception e)
      {
      output.Write(SPEncode.HtmlEncode(e.Message.ToString()));
      }
}

posted Monday, November 21, 2005 8:31 PM by admin with 0 Comments

Powered by Community Server, by Telligent Systems