利用marquee,滚动显示sps站点中的列表内容。
此webpart中有有四个参数:
Site URL:站点的url地址
ListName:列表的名字
using
System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Portal.Topology ;
using Microsoft.SharePoint.Portal;
using Microsoft.SharePoint.Portal.SiteData;
using Microsoft.SharePoint.WebControls;
using System.Collections;
namespace Sharepoint.Adainat.MarqueeListings
{
/**//// <summary>
/// Summary description for MarqueeGroupedListings.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:MarqueeGroupedListings runat=server></{0}:MarqueeGroupedListings>"),
XmlRoot(Namespace="MarqueeListings")]
public class MarqueeGroupedListings : Microsoft.SharePoint.WebPartPages.WebPart
{
private const string siteURL = "";
private string _URL = siteURL;
[Browsable(true),Category("Marquee Options"),
DefaultValue(siteURL),
WebPartStorage(Storage.Personal),
FriendlyName("Site URL"),Description("Site URL")]
public string URL
{
get
{
return _URL;
}
set
{
_URL = value;
}
}
private const string listname="Events";
private string _list=listname;
[Browsable(true),Category("Marquee Options"),
DefaultValue(listname),
WebPartStorage(Storage.Personal),
FriendlyName("List Name"),Description("List Name")]
public string list
{
get
{
return _list;
}
set
{
_list = value;
}
}
private const string fieldname="Title";
private string _displayfieldname=fieldname;
[Browsable(true),Category("Marquee Options"),
DefaultValue(fieldname),
WebPartStorage(Storage.Personal),
FriendlyName("Display Field Name"),Description("Display Field Name")]
public string displayfieldname
{
get
{
return _displayfieldname;
}
set
{
_displayfieldname = value;
}
}
private const string linkname="";
private string _hyperlinkname=linkname;
[Browsable(true),Category("Marquee Options"),
DefaultValue(linkname),
WebPartStorage(Storage.Personal),
FriendlyName("Hyper link address"),Description("Hyper link address")]
public string hyperlinkname
{
get
{
return _hyperlinkname;
}
set
{
_hyperlinkname = value;
}
}
private const string marqparm="scrolldelay=350";
private string _marqeeparam=marqparm;
[Browsable(true),Category("Marquee Options"),
DefaultValue(marqparm),
WebPartStorage(Storage.Personal),
FriendlyName("Marqee Parameters"),Description("Marqee Parameters")]
public string marqeeparam
{
get
{
return _marqeeparam;
}
set
{
_marqeeparam = value;
}
}
public override ToolPart[] GetToolParts()
{
ToolPart[] toolparts = new ToolPart[3];
WebPartToolPart wptp = new WebPartToolPart();
CustomPropertyToolPart custom = new CustomPropertyToolPart();
toolparts[1] = wptp;
toolparts[0] = custom;
toolparts[2] = new Copyright();
return toolparts;
}
protected override void RenderWebPart(HtmlTextWriter output)
{
try
{
SPList listings=GetListings(this.URL.ToString());
if (listings!=null)
{
if (listings.Items.Count>0)
{
string str="";
int counter=0;
ArrayList textArrayList = new ArrayList();
ArrayList linkArrayList = new ArrayList();
//this is order the last one entered appears in the first
int TotalNewNUm=0;
foreach (SPListItem li in listings.Items)
{
textArrayList.Add (li[this.displayfieldname].ToString());
linkArrayList.Add (this.hyperlinkname+li.ID.ToString());
TotalNewNUm++;
}//foreach
int i ;
for(i=TotalNewNUm-1 ;i>=0 ;i--)
{
str+= "<a href=" + linkArrayList[i] + " target=_blank > <span style='font-family:verdana ; font-size: 8pt ; height:10px; margin-bottom:3px; '>" + textArrayList[i] + "</span> </a>" ;
counter++;
if (i !=0)
{
str+= " " ;
}
}
//<marquee id="scroll" scrollamount=1 scrolldelay=90 direction=up width=180 height=150
output.Write( " <marquee "+this.marqeeparam.ToString()+" >" + str + "</marquee>" );
}
else
{
output.WriteLine (" There is No listings in this site " + this.URL.ToString() + " !");
}
}
else
{
output.Write ("Wrong site URL address, Go back to the webpart properties to correct the site URL (e.g http://ServerName:port/)");
}
}
catch (Exception e)
{
output.Write ( "Error Message : " + e.Message );
}
}
private SPList GetListings(string url)
{
SPSite siteCollection;
SPWeb site ;
try
{
if (url=="")
{
siteCollection = SPControl.GetContextSite(Context);
site = SPControl.GetContextWeb(Context);
}
else
{
siteCollection = new SPSite(url);
site = siteCollection.OpenWeb();
}
SPList list=site.Lists[this.list];
return list;
}
catch (Exception)
{
return null;
}
}
}
}
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Portal.Topology ;
using Microsoft.SharePoint.Portal;
using Microsoft.SharePoint.Portal.SiteData;
using Microsoft.SharePoint.WebControls;
using System.Collections;
namespace Sharepoint.Adainat.MarqueeListings
{
/**//// <summary>
/// Summary description for MarqueeGroupedListings.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:MarqueeGroupedListings runat=server></{0}:MarqueeGroupedListings>"),
XmlRoot(Namespace="MarqueeListings")]
public class MarqueeGroupedListings : Microsoft.SharePoint.WebPartPages.WebPart
{
private const string siteURL = "";
private string _URL = siteURL;
[Browsable(true),Category("Marquee Options"),
DefaultValue(siteURL),
WebPartStorage(Storage.Personal),
FriendlyName("Site URL"),Description("Site URL")]
public string URL
{
get
{
return _URL;
}
set
{
_URL = value;
}
}
private const string listname="Events";
private string _list=listname;
[Browsable(true),Category("Marquee Options"),
DefaultValue(listname),
WebPartStorage(Storage.Personal),
FriendlyName("List Name"),Description("List Name")]
public string list
{
get
{
return _list;
}
set
{
_list = value;
}
}
private const string fieldname="Title";
private string _displayfieldname=fieldname;
[Browsable(true),Category("Marquee Options"),
DefaultValue(fieldname),
WebPartStorage(Storage.Personal),
FriendlyName("Display Field Name"),Description("Display Field Name")]
public string displayfieldname
{
get
{
return _displayfieldname;
}
set
{
_displayfieldname = value;
}
}
private const string linkname="";
private string _hyperlinkname=linkname;
[Browsable(true),Category("Marquee Options"),
DefaultValue(linkname),
WebPartStorage(Storage.Personal),
FriendlyName("Hyper link address"),Description("Hyper link address")]
public string hyperlinkname
{
get
{
return _hyperlinkname;
}
set
{
_hyperlinkname = value;
}
}
private const string marqparm="scrolldelay=350";
private string _marqeeparam=marqparm;
[Browsable(true),Category("Marquee Options"),
DefaultValue(marqparm),
WebPartStorage(Storage.Personal),
FriendlyName("Marqee Parameters"),Description("Marqee Parameters")]
public string marqeeparam
{
get
{
return _marqeeparam;
}
set
{
_marqeeparam = value;
}
}
public override ToolPart[] GetToolParts()
{
ToolPart[] toolparts = new ToolPart[3];
WebPartToolPart wptp = new WebPartToolPart();
CustomPropertyToolPart custom = new CustomPropertyToolPart();
toolparts[1] = wptp;
toolparts[0] = custom;
toolparts[2] = new Copyright();
return toolparts;
}
protected override void RenderWebPart(HtmlTextWriter output)
{
try
{
SPList listings=GetListings(this.URL.ToString());
if (listings!=null)
{
if (listings.Items.Count>0)
{
string str="";
int counter=0;
ArrayList textArrayList = new ArrayList();
ArrayList linkArrayList = new ArrayList();
//this is order the last one entered appears in the first
int TotalNewNUm=0;
foreach (SPListItem li in listings.Items)
{
textArrayList.Add (li[this.displayfieldname].ToString());
linkArrayList.Add (this.hyperlinkname+li.ID.ToString());
TotalNewNUm++;
}//foreach
int i ;
for(i=TotalNewNUm-1 ;i>=0 ;i--)
{
str+= "<a href=" + linkArrayList[i] + " target=_blank > <span style='font-family:verdana ; font-size: 8pt ; height:10px; margin-bottom:3px; '>" + textArrayList[i] + "</span> </a>" ;
counter++;
if (i !=0)
{
str+= " " ;
}
}
//<marquee id="scroll" scrollamount=1 scrolldelay=90 direction=up width=180 height=150
output.Write( " <marquee "+this.marqeeparam.ToString()+" >" + str + "</marquee>" );
}
else
{
output.WriteLine (" There is No listings in this site " + this.URL.ToString() + " !");
}
}
else
{
output.Write ("Wrong site URL address, Go back to the webpart properties to correct the site URL (e.g http://ServerName:port/)");
}
}
catch (Exception e)
{
output.Write ( "Error Message : " + e.Message );
}
}
private SPList GetListings(string url)
{
SPSite siteCollection;
SPWeb site ;
try
{
if (url=="")
{
siteCollection = SPControl.GetContextSite(Context);
site = SPControl.GetContextWeb(Context);
}
else
{
siteCollection = new SPSite(url);
site = siteCollection.OpenWeb();
}
SPList list=site.Lists[this.list];
return list;
}
catch (Exception)
{
return null;
}
}
}
}
Display Field Name:显示的列表字段的名字
Hyper Link address:超链接的地址
下面是源代码,各位可以参考参考.