Sunday, November 14, 2010

Get details from announcment list

using (site = SPContext.Current.Site)
{
using (web = SPContext.Current.Web)
{
myLib = web.Lists["Announcements"];
libItems = myLib.Items;
if (libItems.Count == 0)
{
lblMsg.Text = "There are no items to show in this \"" + myLib.ToString() + "\"";
clearGrid();
}
else
lblMsg.Text = "";
libItems = myLib.Items;
DataTable dt = new DataTable();
dt.Columns.Add("ImageURL", typeof(string));
dt.Columns.Add("Title", typeof(string));
dt.Columns.Add("Body", typeof(string));
dt.Columns.Add("Height", typeof(string));
dt.Columns.Add("Width", typeof(string));
dt.Columns.Add("URL", typeof(string));
dt.Columns.Add("UName", typeof(string));
dt.Columns.Add("Time", typeof(string));
dt.Columns.Add("AddNew", typeof(string));
if (libItems.Fields.ContainsField("Body") == true && libItems.Fields.ContainsField("ImageURL") == true)
{
foreach (SPListItem item in libItems)
{
string imageURL = item["ImageURL"].ToString();
string title = item["Title"].ToString();
string body = item["Body"].ToString();
string listURL = myLib.DefaultDisplayFormUrl +"?ID="+item.ID;
string userName = item["Author"].ToString();
string[] uName = userName.Split('#');
string Time = item["Created"].ToString();
string addNew = item.Web.Url + myLib.DefaultNewFormUrl;
int length = body.Length;
if (length >= 200)
body = body.Substring(0, 200) + "...";
dt.Rows.Add(imageURL, title, body, strPtyImgHeight, strPtyImgWidth, listURL,uName[1], Time, addNew);
}
dtlGetAnnouncement.DataSource = dt;
dtlGetAnnouncement.DataBind();
hlnkAddnew.NavigateUrl = web.Url + myLib.DefaultNewFormUrl; ;
}
else if (libItems.Fields.ContainsField("Body") == false)
{
lblMsg.Text = "There are no Column Name 'Body' in your \"" + myLib.ToString() + "\"";
clearGrid();
}
else if (libItems.Fields.ContainsField("ImageURL") == false)
{
lblMsg.Text = "There are no Column Name 'ImageURL' in your \"" + myLib.ToString() + "\"";
clearGrid();
}
}
}

No comments:

Post a Comment

How to launch a document by clicking a link to the file?

Word: <a href='ms-word:ofe|u|path/to/web/word/document.docx'>Link to document</a> Excel: <a href='ms-excel:o...