滚动显示sps站点中某个列表里面的内容的 webpart

利用marquee,滚动显示sps站点中的列表内容。
此webpart中有有四个参数:
Site URL:站点的url地址
ListName:列表的名字

None.gif using  System;
None.gif
None.gif
using  System.ComponentModel;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Xml.Serialization;
None.gif
using  Microsoft.SharePoint;
None.gif
using  Microsoft.SharePoint.Utilities;
None.gif
using  Microsoft.SharePoint.WebPartPages;
None.gif
using  Microsoft.SharePoint.Portal.Topology ;
None.gif
using  Microsoft.SharePoint.Portal;
None.gif
using  Microsoft.SharePoint.Portal.SiteData;
None.gif
using  Microsoft.SharePoint.WebControls;
None.gif
None.gif
using  System.Collections;
None.gif
None.gif
namespace  Sharepoint.Adainat.MarqueeListings
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Summary description for MarqueeGroupedListings.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    [DefaultProperty("Text"),
InBlock.gif        ToolboxData(
"<{0}:MarqueeGroupedListings runat=server></{0}:MarqueeGroupedListings>"),
InBlock.gif        XmlRoot(Namespace
="MarqueeListings")]
InBlock.gif    
public class MarqueeGroupedListings : Microsoft.SharePoint.WebPartPages.WebPart
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
private const string siteURL = "";
InBlock.gif        
private string _URL = siteURL;
InBlock.gif
InBlock.gif        [Browsable(
true),Category("Marquee Options"),
InBlock.gif        DefaultValue(siteURL),
InBlock.gif        WebPartStorage(Storage.Personal),
InBlock.gif        FriendlyName(
"Site URL"),Description("Site URL")]
InBlock.gif        
public string URL
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _URL;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _URL 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif        
private const string listname="Events";
InBlock.gif        
private string _list=listname;
InBlock.gif        [Browsable(
true),Category("Marquee Options"),
InBlock.gif        DefaultValue(listname),
InBlock.gif        WebPartStorage(Storage.Personal),
InBlock.gif        FriendlyName(
"List Name"),Description("List Name")]
InBlock.gif        
public string list
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _list;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _list 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif        
private const string fieldname="Title";
InBlock.gif        
private string _displayfieldname=fieldname;
InBlock.gif        [Browsable(
true),Category("Marquee Options"),
InBlock.gif        DefaultValue(fieldname),
InBlock.gif        WebPartStorage(Storage.Personal),
InBlock.gif        FriendlyName(
"Display Field Name"),Description("Display Field Name")]
InBlock.gif        
public string displayfieldname
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _displayfieldname;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _displayfieldname 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private const string linkname="";
InBlock.gif        
private string _hyperlinkname=linkname;
InBlock.gif        [Browsable(
true),Category("Marquee Options"),
InBlock.gif        DefaultValue(linkname),
InBlock.gif        WebPartStorage(Storage.Personal),
InBlock.gif        FriendlyName(
"Hyper link address"),Description("Hyper link address")]
InBlock.gif        
public string hyperlinkname
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _hyperlinkname;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _hyperlinkname 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private const string marqparm="scrolldelay=350";
InBlock.gif        
private string _marqeeparam=marqparm;
InBlock.gif        [Browsable(
true),Category("Marquee Options"),
InBlock.gif        DefaultValue(marqparm),
InBlock.gif        WebPartStorage(Storage.Personal),
InBlock.gif        FriendlyName(
"Marqee Parameters"),Description("Marqee Parameters")]
InBlock.gif        
public string marqeeparam
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _marqeeparam;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _marqeeparam 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public override ToolPart[] GetToolParts()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ToolPart[] toolparts 
= new ToolPart[3];
InBlock.gif            WebPartToolPart wptp 
= new WebPartToolPart();
InBlock.gif            CustomPropertyToolPart custom 
= new CustomPropertyToolPart();
InBlock.gif            toolparts[
1= wptp;
InBlock.gif            toolparts[
0= custom;
InBlock.gif            toolparts[
2= new Copyright();
InBlock.gif            
return toolparts;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
protected override void RenderWebPart(HtmlTextWriter output)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                SPList listings
=GetListings(this.URL.ToString());
InBlock.gif                 
if (listings!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (listings.Items.Count>0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
string str="";
InBlock.gif                        
int counter=0;
InBlock.gif                        ArrayList textArrayList 
= new ArrayList();
InBlock.gif                        ArrayList linkArrayList 
= new ArrayList();
InBlock.gif                        
//this is order the last one entered appears in the first
InBlock.gif
                        int TotalNewNUm=0;
InBlock.gif
InBlock.gif                        
foreach (SPListItem li in listings.Items)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            textArrayList.Add (li[
this.displayfieldname].ToString());
InBlock.gif                            linkArrayList.Add (
this.hyperlinkname+li.ID.ToString());
InBlock.gif                            TotalNewNUm
++;
InBlock.gif                                                            
ExpandedSubBlockEnd.gif                        }
//foreach
InBlock.gif
                        int i ;
InBlock.gif                        
for(i=TotalNewNUm-1 ;i>=0  ;i--)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            str
+= "<a href=" + linkArrayList[i] + " target=_blank > <span style='font-family:verdana ; font-size: 8pt ;  height:10px; margin-bottom:3px; '>" + textArrayList[i] + "</span> </a>" ;                              
InBlock.gif                            counter
++;
InBlock.gif                            
if (i !=0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif                                str
+=   "     " ;
ExpandedSubBlockEnd.gif                            }

ExpandedSubBlockEnd.gif                        }

InBlock.gif                    
//<marquee id="scroll" scrollamount=1 scrolldelay=90 direction=up width=180 height=150
InBlock.gif
                     output.Write( " <marquee "+this.marqeeparam.ToString()+" >" + str + "</marquee>" );
InBlock.gif                                     
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                    output.WriteLine (
" There is No listings in this site  " + this.URL.ToString() + " !");
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    output.Write (
"Wrong site URL address, Go back to the webpart properties to correct the site URL (e.g http://ServerName:port/)");
ExpandedSubBlockEnd.gif                }

InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif                    
InBlock.gif            
catch (Exception e)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                output.Write (   
"Error Message : " + e.Message   );
InBlock.gif                
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
private SPList GetListings(string url)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            SPSite siteCollection;
InBlock.gif            SPWeb site ;
InBlock.gif
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (url=="")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    siteCollection 
= SPControl.GetContextSite(Context); 
InBlock.gif                    site 
= SPControl.GetContextWeb(Context);         
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    siteCollection 
= new SPSite(url);
InBlock.gif                    site 
= siteCollection.OpenWeb();
ExpandedSubBlockEnd.gif                }

InBlock.gif            
InBlock.gif                SPList list
=site.Lists[this.list];            
InBlock.gif                
return list;
InBlock.gif                
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                 
return null;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }
  
InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif


Display Field Name:显示的列表字段的名字
Hyper Link address:超链接的地址
下面是源代码,各位可以参考参考.

转载于:https://www.cnblogs.com/musicz/archive/2005/08/30/225952.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值