1

I am getting started with sp2010 dev and I am looking to build a visual web part(sandboxed) image banner, which will loop through user specified image library. The image changes on page refresh.My questions are,

1) Is there is a similar control out there which i could reuse or modify to my specifics so I need not reinvent the wheel. If not could give me a little insight on the approach please?

2) I would like some input on how to add the control to Master Page (v4.Master).

Thanks and Appreciate your help and replies :)

0

2 Answers 2

1

You can save images in a asset library and then get images from the library and display them in your user control which you can then add it to the master page. The logic will be:

You can add a column to the asset library calles Sequence Number. You can display the first image on load and save it as session variable and on next load you can load the next session number and persist the current in session.

In your control just use a simple CAML to get by Sequence Number.

        SPSite oSite = SPContext.Current.Site;
        SPWeb oWeb = oSite.OpenWeb();
        SPList oList = oWeb.Lists["ListName"];
        SPQuery oQuery = new SPQuery();
        oQuery.Query = "<Where>"
            + "<FieldRef Name='SequenceNumber' /><Value Type='Integer'>2</Value></Where>";
        SPListItemCollection oItems = oList.GetItems(oQuery);

Add the dll reference to the top in your master page and add your control to the page.

1
  • On the same note, i did query the Listitems and used Random method of dotnet to display image. Now, If i add this as control to MasterPage, how to configure properties of web part? For ex: ListName is a property of web part. Please elaborate. Thanks ! Commented Jul 22, 2012 at 21:22
1
  1. This product is quite nice and does the trick for me at least. I have no affiliations with the product what so ever. Path To SharePoint - Image Rotator. Have fun.
  2. Open your masterpage in SharePoint Designer and insert it via the SPD UI. Or if it's a masterpage deployed via Visual Studio, register your visual webpart as a webusercontrol like so:

Example:

<%@ Register TagPrefix="<prefix>" TagName="<tagname>" src="<src>" %>

<%@ Register TagPrefix="Dandroid" TagName="ImageRotator" src="~/_controltemplates/dandroidcontrols/imagerotator.ascx" %>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.