博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Sharepoint 2010 实现图片新闻轮播
阅读量:6064 次
发布时间:2019-06-20

本文共 3879 字,大约阅读时间需要 12 分钟。

项目需要实现图片轮播的效果,没找到资料,自己上网找了一个物效,然后自己整合进sharepoint 2010,不说废话,下面是源码:

photoNewsUserControl.ascx

 

<div>

<% photo(); %>

<script type="text/javascript">

    var pic_width = 420; //图ª?片?宽¨ª度¨¨ 420*280

    var pic_height = 260; //图ª?片?高?度¨¨

    var text_height = 30; //文?字Á?高?度¨¨

    var swfpath = '/_layouts/images/flashFocus01.swf'; //swf文?件t路¡¤径?地Ì?址¡¤

    var swf_height = pic_height + text_height;

    var pics = "", links = "", texts = "";

    for (var i = 0; i < 3; i++) {

        pics = pics + ("|" + imag[i]);

        links = links + ("|" + link[i]);

        texts = texts + ("|" + text[i]);

    }

    pics = pics.substring(1);

    links = links.substring(1);

    texts = texts.substring(1);

    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + pic_width + '" height="' + swf_height + '">');

    document.write('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="' + swfpath + '"><param name="quality" value="high"><param name="bgcolor" value="#E1F2FF">');

    document.write('<param name="menu" value="false"><param name=wmode value="opaque">');

    document.write('<param name="FlashVars" value="pics=' + pics + '&links=' + links + '&texts=' + texts + '&borderwidth=' + pic_width + '&borderheight=' + pic_height + '&textheight=' + text_height + '">');

    document.write('<embed src="' + swfpath + '" wmode="opaque" FlashVars="pics=' + pics + '&links=' + links + '&texts=' + texts + '&borderwidth=' + pic_width + '&borderheight=' + pic_height + '&textheight=' + text_height + '" menu="false" bgcolor="#FFFFFF" quality="high" width="' + pic_width + '" height="' + pic_height + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');

    document.write('</object>');

</script>

</div>

 

photoNewsUserControl.ascx.cs

 

namespace SharePointProject.photoNews

{

    public partial class photoNewsUserControl : UserControl

    {

        protected void Page_Load(object sender, EventArgs e)

        {

 

        }

        public void photo()

        {

            try

            {

                SPSite manageSite = null;

                SPWeb manageWeb = null;

                SPSecurity.RunWithElevatedPrivileges(delegate

                {

                    using (manageSite = new SPSite(SPContext.Current.Site.ID))

                    {

                        using (manageWeb = manageSite.OpenWeb(manageSite.RootWeb.ID))

                        {

                            SPList list = manageWeb.GetList("Lists/List2");

                            SPQuery myQuery = new SPQuery();

                            myQuery.Query = "<Where><Contains><FieldRef Name='_x5185__x5bb9_' /><Value Type='Note'>img</Value></Contains></Where><OrderBy><FieldRef Name='Modified' Ascending='False' /></OrderBy>";

                            myQuery.RowLimit = 3;

                            SPListItemCollection spc = list.GetItems(myQuery);

                            DataTable dt = spc.GetDataTable();

                            if (dt.Rows.Count > 0)

                            {

                                string str = "";

                                for (int i = 0; i < dt.Rows.Count; i++)

                                {

                                    string[] imag = new string[3];

                                    string[] link = new string[3];

                                    string[] text = new string[3];

                                    imag[i] = getImgUrl(dt.Rows[i]["_x5185__x5bb9_"].ToString());

                                    link[i] = "http://" + Request.Url.Authority + "/pages/listdetail.aspx?picid=" + dt.Rows[i]["ID"].ToString();

                                    text[i] = dt.Rows[i]["title"].ToString().Length > 10 ? dt.Rows[i]["title"].ToString().Substring(0, 10) + "..." : dt.Rows[i]["title"].ToString();

                                    str += "imag[" + i + "]='" + imag[i] + "';";

                                    str += "link[" + i + "]='" + link[i] + "';";

                                    str += "text[" + i + "]='" + text[i] + "';";

 

                                }

                                string abc = "<script language='javascript'>";

                                abc += "var imag=new Array();var link=new Array();var text=new Array();";

                                abc += str;

                                abc += "</script>";

                                Response.Write(abc);

                            }

                        }

                    }

 

                });

                

            }

            catch { }

        }

 

        public string getImgUrl(string html)

        {

            string url = "";

            Regex reg = new Regex(@"(?i)<img[^>]*?src=(['""]?)([^'""\s>]+)\1[^>]*>");

            Match m = reg.Match(html);

            if (m.Success)

            {

                if (m.Groups[2].Value.Contains("http"))

                {

                    url = m.Groups[2].Value;

                }

                else

                {

                    url = "http://" + Request.Url.Authority + m.Groups[2].Value;

                }

            }

            return url;

        }

    }

}

效果如下:

 

 

说明 :你输出的数组大小就是显示的图片数量

转载于:https://www.cnblogs.com/rimtd/p/3284453.html

你可能感兴趣的文章
伪数组 arguments
查看>>
Redis的删除机制、持久化 主从
查看>>
LINGO中的集
查看>>
用vue实现简单实时汇率计算功能
查看>>
对数组的排序
查看>>
postgresql----数据库表约束----PRIMARY KEY
查看>>
亿级Web系统搭建——单机到分布式集群
查看>>
fre7 offonline for firefox
查看>>
深度搜索--poj3984 迷宫问题
查看>>
鼠标悬浮时,蒙版显示;否则,蒙版消失
查看>>
[置顶] Asp.net中实现多语言的Page的扩展的基类
查看>>
SqlServer中 将某个表的某个字段改个默认值
查看>>
IOS笔记-和新语法
查看>>
[LeetCode] Valid Number
查看>>
【转】HTML5移动端最新兼容问题解决方案
查看>>
sql server遍历表不用游标和临时表的方法
查看>>
yii使用gii创建后台模块与widget使用
查看>>
sqlserver 索引优化 CPU占用过高 执行分析 服务器检查
查看>>
C++最后课程项目总结
查看>>
BZOJ4552:[HEOI2016/TJOI2016]排序——题解
查看>>