- totd.zip
- TOTD
- bin
- Features
- Feature1
- key.snk
- Package
- pkg
- Debug
- TOTD
- CONTROLTEMPLATES
- TOTD
- TOTD
- manifest.xml
- TOTD.dll
- TOTD_Feature1
- pkgobj
- Debug
- Properties
- TOTD.csproj
- TOTD.csproj.user
- TOTD
|
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using Microsoft.SharePoint.Utilities;
namespace TOTD.VisualWebPart1
{
public partial class VisualWebPart1UserControl : UserControl
{
//Design by Lalith Gallage
protected void Page_Load(object sender, EventArgs e)
{
SPWeb oWebsite = SPContext.Current.Web;
SPList oList = oWebsite.Lists["QOTD"];
SPListItemCollection collItem = oList.GetItems("Thought", "AuthorImage", "AuthorName");
Random random = new Random();
int RndItem = random.Next(1, collItem.Count+1);
int LastDay = 0;
int TOTD = 0;
int CurrentDay = DateTime.Now.DayOfYear;
try
{
LastDay = int.Parse(Application["LastDay"].ToString());
TOTD = int.Parse(Application["TOTD"].ToString());
if (LastDay != CurrentDay)
{
Application["LastDay"] = CurrentDay;
Application["TOTD"] = RndItem;
SPListItem oItem = collItem[RndItem-1];
this.ImgAuthor.ImageUrl = SPEncode.HtmlEncode(oItem["AuthorImage"].ToString().TrimEnd('?', '.', ',', ' '));
this.lblTOTD.Text = oItem["Thought"].ToString();
this.lblAuthor.Text = SPEncode.HtmlEncode(oItem["AuthorName"].ToString());
}
else
{
SPListItem oItem = collItem[TOTD-1];
this.ImgAuthor.ImageUrl = SPEncode.HtmlEncode(oItem["AuthorImage"].ToString().TrimEnd('?', '.', ',', ' '));
this.lblTOTD.Text = oItem["Thought"].ToString();
this.lblAuthor.Text = SPEncode.HtmlEncode(oItem["AuthorName"].ToString());
}
}
catch
{
Application["LastDay"] = CurrentDay;
Application["TOTD"] = RndItem;
SPListItem oItem = collItem[RndItem - 1];
this.ImgAuthor.ImageUrl = SPEncode.HtmlEncode(oItem["AuthorImage"].ToString().TrimEnd('?', '.', ',', ' '));
this.lblTOTD.Text = oItem["Thought"].ToString();
this.lblAuthor.Text = SPEncode.HtmlEncode(oItem["AuthorName"].ToString());
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.