代码在内容编辑器 Web 部件 SharePoint 2007 中不起作用
我仍在尝试找出需要在 SharePoint 2007 中显示的幻灯片任务。在我的其他帖子中,人们建议做一些我不愿意或没有技能承担的更具挑战性的事情。所以我这里可能是一个更简单的解决方案,但它也不起作用。
我正在使用内容编辑器 Web 部件,我将在独立网站中运行的代码复制到其中,但在此处不起作用。
我希望你能告诉我这是否可行并提出修复建议,或者我应该将其全部废弃并接受之前的挑战。
在default.master中我有这样的Javascript:
<script language="javascript" type="text/javascript">
<!--
var slideimages=new Array()
var slidelinks=new Array()
function slideshowimages(){
for (i=0;i<slideshowimages.arguments.length;i++){
slideimages[i]=new Image()
slideimages[i].src=slideshowimages.arguments[i]
}
}
function slideshowlinks(){
for (i=0;i<slideshowlinks.arguments.length;i++)
slidelinks[i]=slideshowlinks.arguments[i]
}
function gotoshow(){
if (!window.winslide||winslide.closed)
winslide=window.open(slidelinks[whichlink])
else
winslide.location=slidelinks[whichlink]
winslide.focus()
}
//-->
然后在内容编辑器 Web 部件中我有以下内容:
<script runat="server" >
protected void Page_Load(object sender, EventArgs e)
{
int iCounter = 0;
string path = Server.MapPath("/Bulletin/");
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(path);
System.IO.FileInfo[] slides = di.GetFiles("*.jpg");
iCounter = slides.Length;
string mystring = string.Empty;
int i = 0;
foreach (System.IO.FileInfo file in slides)
{
if (i < iCounter-1)
{
mystring += "'/Bulletin/" + slides[i].ToString() + "',";
i++;
}
else
{
mystring += "'/Bulletin/" + slides[i].ToString() + "'";
}
}
String scriptString = @"<script language=JavaScript>";
scriptString += @"slideshowimages(" + mystring + @")
slideshowlinks() // Still need to build this up
var slideshowspeed = 10000
var whichlink = 0
var whichimage = 0
function slideit() {
if (!document.images)
return
document.images.slide.src = slideimages[whichimage].src
whichlink = whichimage
if (whichimage < slideimages.length - 1)
whichimage++
else
whichimage = 0
setTimeout('slideit()', slideshowspeed)
}
slideit()
";
scriptString += @"</";
scriptString += @"script>";
if (!this.IsStartupScriptRegistered("clientScript"))
this.RegisterStartupScript("clientScript", scriptString.ToString());
}
我尝试将所有内容放入 Web 部件中。我还将 JavaScript 放在自己的文件中,放在应用程序根目录的脚本目录中,并这样调用它。我还复制了 /_layout/1033 目录,但这些步骤都没有帮助。
谢谢您的宝贵时间!
I'm still trying to figure out this slideshow task that I need to display in a SharePoint 2007. In my other post folks suggested doing things that are more challenging that I'm not willing or have skills to take on. So what I have here is perhaps a simpler solution but it's not working either.
I'm using a content editor web part into which I copied the code that works in a stand alone web site but not here.
I was hoping you can tell me if this can work and suggest a fix or should I just scrap it all toghether and take on the prior challenge.
In the default.master I have Javascript like this:
<script language="javascript" type="text/javascript">
<!--
var slideimages=new Array()
var slidelinks=new Array()
function slideshowimages(){
for (i=0;i<slideshowimages.arguments.length;i++){
slideimages[i]=new Image()
slideimages[i].src=slideshowimages.arguments[i]
}
}
function slideshowlinks(){
for (i=0;i<slideshowlinks.arguments.length;i++)
slidelinks[i]=slideshowlinks.arguments[i]
}
function gotoshow(){
if (!window.winslide||winslide.closed)
winslide=window.open(slidelinks[whichlink])
else
winslide.location=slidelinks[whichlink]
winslide.focus()
}
//-->
Then in content editor web part I have this:
<script runat="server" >
protected void Page_Load(object sender, EventArgs e)
{
int iCounter = 0;
string path = Server.MapPath("/Bulletin/");
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(path);
System.IO.FileInfo[] slides = di.GetFiles("*.jpg");
iCounter = slides.Length;
string mystring = string.Empty;
int i = 0;
foreach (System.IO.FileInfo file in slides)
{
if (i < iCounter-1)
{
mystring += "'/Bulletin/" + slides[i].ToString() + "',";
i++;
}
else
{
mystring += "'/Bulletin/" + slides[i].ToString() + "'";
}
}
String scriptString = @"<script language=JavaScript>";
scriptString += @"slideshowimages(" + mystring + @")
slideshowlinks() // Still need to build this up
var slideshowspeed = 10000
var whichlink = 0
var whichimage = 0
function slideit() {
if (!document.images)
return
document.images.slide.src = slideimages[whichimage].src
whichlink = whichimage
if (whichimage < slideimages.length - 1)
whichimage++
else
whichimage = 0
setTimeout('slideit()', slideshowspeed)
}
slideit()
";
scriptString += @"</";
scriptString += @"script>";
if (!this.IsStartupScriptRegistered("clientScript"))
this.RegisterStartupScript("clientScript", scriptString.ToString());
}
I have tried placing everything in the webpart. I have also placed the JavaScript in its own file, placed in a script directory in the root of my app and call it like that. I have also copied in the /_layout/1033 directory but none of these steps helped.
Thank you for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法在内容编辑 Web 部件中执行服务器端代码。
<script runat="server" >
You cannot execute server side code in content edit web part.