I have observed that SharePoint Hyperlink Field and SharePoint Image Field accepts only 255 characters. Suppose if we are giving URL of big size then the Hyperlink or Image Teat box in SharePoint will not accept. Alternative solution for this is use Plain Multiple lines of Text instead of Hyperlink or Image Field.
Wednesday, October 31, 2012
Tuesday, October 30, 2012
Real Time Task Binding Count Based on Colors in SharePoint 2007 and SharePoint 2010 Dynamically.
Back End Database
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Security;
namespace CHSample1.CHSample1
{
[ToolboxItemAttribute(false)]
public class CHSample1 : WebPart
{
string strError = string.Empty;
string strHTML = string.Empty;
protected override void Render(HtmlTextWriter
writer)
{
try
{
SPWeb currentWeb = SPContext.Current.Web;
SPList lst = currentWeb.Lists["Color"];
SPQuery sQuery = new SPQuery();
sQuery.Query = "<OrderBy><FieldRef
Name='ID' /></OrderBy>";
SPListItemCollection myColl =
lst.GetItems(sQuery);
if (myColl.Count > 0)
{
string strTable = string.Empty;
strTable += "<Table>";
foreach (SPListItem
item in myColl)
{
string strColor = string.Empty;
strColor =
item.Title.ToString();
int i = BindTaskCount(strColor);
strTable += "<Tr>";
strTable += "<Td style='background-color:"+strColor+"' Title='"+strColor+"' width='10'>";
strTable += " ";
strTable += "</Td>";
strTable += "<Td>";
strTable += " ";
strTable += "</Td>";
strTable += "<Td>";
strTable += i;
strTable += "</Td>";
strTable += "</Tr>";
}
strTable += "</Table>";
writer.Write(strTable);
}
}
catch (Exception
ex)
{
writer.Write(ex.ToString());
}
}
public int
BindTaskCount(string strColor)
{
SPWeb currentWeb = SPContext.Current.Web;
SPList lst = currentWeb.Lists["New Tasks"];
SPQuery sQuery = new SPQuery();
sQuery.Query = "<Where><Eq><FieldRef
Name='Color' /><Value Type='Lookup'>" + strColor + "</Value></Eq></Where><OrderBy><FieldRef
Name='Color' /></OrderBy>";
int count = 0;
SPListItemCollection myColl =
lst.GetItems(sQuery);
if (myColl.Count > 0)
{
count = myColl.Count;
}
return count;
}
}
}
Binding Image along with Count of Tasks Real Time Task in SharePoint 2007 and SharePoint 2010
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Security;
namespace CHSample.CHSample
{
[ToolboxItemAttribute(false)]
public class CHSample : WebPart
{
int strTaskCompleted;
int StrTaskInProgress;
int strTaskNotStarted;
int strtaskDeferred;
int strWaitingOnSomeoneElse;
string strTaskCompletedImage=SPContext.Current.Web.Url+"/Shared Documents/Completed.JPG";
string strTaskInProgressImage = SPContext.Current.Web.Url + "/Shared Documents/In Progress.JPG";
string strTaskNotStartedImage = SPContext.Current.Web.Url + "/Shared Documents/Not Started.JPG";
string strTaskDeferredImage = SPContext.Current.Web.Url + "/Shared
Documents/Deferred.JPG";
string
strWaitingOnSomeoneElseImage = SPContext.Current.Web.Url
+ "/Shared Documents/Waiting on Soimeonle
else.JPG";
string strError = string.Empty;
protected override void Render(HtmlTextWriter
writer)
{
writer.Write(strError);
try
{
writer.Write("<Table>");
//Completed Status
writer.Write("<Tr>");
writer.Write("<Td>");
writer.Write("<img src='"+strTaskCompletedImage+"' Title='Completed' border='0' width='25'
height='25' />");
writer.Write("</Td>");
writer.Write("<Td>");
writer.Write(strTaskCompleted);
writer.Write("</Td>");
writer.Write("</Tr>");
//In Progress Status
writer.Write("<Tr>");
writer.Write("<Td>");
writer.Write("<img src='"
+ strTaskInProgressImage + "' Title='In
Progress' border='0' width='25' height='25' />");
writer.Write("</Td>");
writer.Write("<Td>");
writer.Write(StrTaskInProgress);
writer.Write("</Td>");
writer.Write("</Tr>");
//Deferred Status
writer.Write("<Tr>");
writer.Write("<Td>");
writer.Write("<img src='"
+ strTaskDeferredImage + "' Title='Deferred'
border='0' width='25' height='25' />");
writer.Write("</Td>");
writer.Write("<Td>");
writer.Write(strtaskDeferred);
writer.Write("</Td>");
writer.Write("</Tr>");
//Waiting on some one else Status
writer.Write("<Tr>");
writer.Write("<Td>");
writer.Write("<img src='"
+ strWaitingOnSomeoneElseImage + "'
Title='Waiting on someone else' border='0' width='25' height='25' />");
writer.Write("</Td>");
writer.Write("<Td>");
writer.Write(strWaitingOnSomeoneElse);
writer.Write("</Td>");
writer.Write("</Tr>");
//Not Started Status
writer.Write("<Tr>");
writer.Write("<Td>");
writer.Write("<img src='" + strTaskNotStartedImage
+ "' Title='Not Started' border='0' width='25'
height='25' />");
writer.Write("</Td>");
writer.Write("<Td>");
writer.Write(strTaskNotStarted);
writer.Write("</Td>");
writer.Write("</Tr>");
writer.Write("</Table>");
}
catch (Exception
ex)
{
writer.Write(ex.ToString());
}
}
protected override void CreateChildControls()
{
try
{
getData("Completed");
getData("In Progress");
getData("Not Started");
getData("Deferred");
getData("Waiting on someone else");
}
catch (Exception
ex)
{
strError += ex.ToString();
}
}
public void getData(string strStatus)
{
try
{
SPWeb
currentWeb = SPContext.Current.Web;
SPList lst = currentWeb.Lists["Tasks"];
SPQuery sQuery = new
SPQuery();
sQuery.Query = "<Where><Eq><FieldRef
Name='Status' /><Value Type='Choice'>" + strStatus + "</Value></Eq></Where>";
SPListItemCollection myColl =
lst.GetItems(sQuery);
if (myColl.Count > 0)
{
if (strStatus == "Completed")
{
strTaskCompleted = myColl.Count;
}
if (strStatus == "Not Started")
{
strTaskNotStarted = myColl.Count;
}
if (strStatus == "Deferred")
{
strtaskDeferred = myColl.Count;
}
if (strStatus == "In Progress")
{
StrTaskInProgress = myColl.Count;
}
if (strStatus == "Waiting on someone else")
{
strWaitingOnSomeoneElse = myColl.Count;
}
}
else
{
if (strStatus == "Completed")
{
strTaskCompleted = 0;
}
if (strStatus == "Not Started")
{
strTaskNotStarted = 0;
}
if (strStatus == "Deferred")
{
strtaskDeferred = 0;
}
if (strStatus == "In Progress")
{
StrTaskInProgress = 0;
}
if (strStatus == "Waiting on someone else")
{
strWaitingOnSomeoneElse = 0;
}
}
}
catch (Exception
ex)
{
strError += ex.ToString();
}
}
}
}
Subscribe to:
Posts (Atom)