New webpart sharepoint : The week in picture

wp_TheWeekInPicture

Download here

Step 1 : create a webpart sharepoint in Visual Studio with the aditional webpart for VS.
Code:

using System;using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.Xml;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace wp_PictureInTheWeek
{
[Guid(“c3622d59-7416-4610-8f96-80127c4b7cd7”)]
public class wp_PictureInTheWeek : System.Web.UI.WebControls.WebParts.WebPart
{
Image myImage;
string pictureListName;

public wp_PictureInTheWeek()
{
this.ExportMode = WebPartExportMode.All;
}

protected override void CreateChildControls()
{
//base.CreateChildControls();
myImage = new Image();
myImage.Width = this.Width;
this.Controls.Add(myImage);

try
{
myImage.ImageUrl = getPathImage();
}
catch (Exception err)
{}
}
//********************************************************************
//********************************************************************
//********************************************************************
[Personalizable(PersonalizationScope.Shared),
WebBrowsable(true),
System.ComponentModel.Category(“Cài đặt riêng”),
WebDisplayName(“Tên list picture :”),
WebDescription(“Tên của list picture library.”)]
public string PictureListName
{
get { return pictureListName; }
set { pictureListName = value; }
}

//********************************************************************
//********************************************************************
//********************************************************************
private string getPathImage()
{
string result = “”;
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists[this.pictureListName];
DateTime dTime = new DateTime();
int index = 0;
for (int i = 0; i < list.Items.Count; i++)
{
if (DateTime.Compare(dTime, DateTime.Parse(list.Items[i][“Modified”].ToString())) < 0)
{
dTime = DateTime.Parse(list.Items[i][“Modified”].ToString());
index = i;
}
}
result = web.Url + “/” + list.Items[index].Url;
return result;
}
}
}

Deploying

Step 2 : Create a picture list contain images that you want to show.

Step 3 : In webpart property of this webpart, type the name of that picture list (step 2)  and the newest image will play when ever you add it.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s