I have a folder of images in my root directory. I created a slide show displayed in the banner using javascript. I populate the javascript array using some code behind logic and ClientScriptManager. All the pages in the root directory display the images and the slideshow runs fine. The problem is I have several pages that are in a folder in the root directory that won't display these images. On my local machine ,I right clicked on the placeholder for where image slideshow is bing displayed and the slideshow is looking for images within the folder that stores those pages. Does anybody have an idea of how I can fix this? Below is the code behind and my script.
Code Behind:
using System;
using System.Collections.Generic
;
using System.Web.UI.WebControls;
using System.Data.Common;
using System.Web.UI;
using System.Text;
using System.IO;
public partial class SWWRP : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
//create a string to hold the images for the banner
StringBuilder imageArray = new StringBuilder();
imageArray = GetImageArray("Banner_Imag
es");
//register array so it can be referenced in javascript
ClientScriptManager csm = Page.ClientScript;
csm.RegisterArrayDeclarati
on("Pictur
es", imageArray.ToString());
}
//build the banner imagearray to be referenced in javascript
protected StringBuilder GetImageArray(string folderName)
{
string Path;
DirectoryInfo Folder;
FileInfo[] Images;
StringBuilder ImageArray = new StringBuilder();
Path = @"c:/inetpub/wwwroot/SWWRP
/Files/" + folderName;
Folder = new DirectoryInfo(Path);
Images = Folder.GetFiles();
// Looping through all files in the folder and generating
// a JavaScript array declaration.
foreach (FileInfo Image in Images)
{
if (Image.Extension.StartsWit
h(".jpg") || Image.Extension.StartsWith
(".JPG"))
ImageArray.AppendFormat("'
{0}/{1}',"
, folderName, Image.Name);
else
continue;
}
if (ImageArray.Length > 0)
{
// Removing the unwanted last comma.
ImageArray.Remove(ImageArr
ay.Length - 1, 1);
}
return ImageArray;
}
Javascript
<html>
<head></head>
<body onload="runSlideShow()">
<div class="fader">
<asp:Image ID="SlideShow" runat="server" name='SlideShow' width="93" height="65" ImageUrl="/Banner_Images/r
enee2.jpg"
/>
</div>
<div class="fader1">
<asp:Image ID="SlideShow1" runat="server" name='SlideShow1' width="93" height="65" ImageUrl="/Banner_Images/r
enee3.jpg"
/>
</div>
</body>
<script language="javascript">
// ==========================
==========
===
// set variables
// ==========================
==========
===
// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 1000;
// Duration of crossfade (seconds)
var crossFadeDuration = 1;
// Specify the image files
var Pic = new Array();
Pic = Pictures;
var Pic1 = new Array();
var p2 = Pic.length;
for (j = p2; j > 0; j--) {
Pic1[p2 - j] = Pic[j - 1];
}
var t;
var j = 0;
var p = Pic.length;
var p1 = Pic1.length;
var preLoad = new Array();
for (i = 0; i < p; i++) {
preLoad[i] = new Image();
preLoad[i].src = Pic[i];
}
var preLoad1 = new Array();
for (i = 0; i < p1; i++) {
preLoad1[i] = new Image();
preLoad1[i].src = Pic1[i];
}
function runSlideShow() {
if (document.all) {
document.images.SlideShow.
style.filt
er = "blendTrans(duration=2)";
document.images.SlideShow.
style.filt
er = "blendTrans(duration=cross
FadeDurati
on)";
document.images.SlideShow.
filters.bl
endTrans.A
pply();
document.images.SlideShow1
.style.fil
ter = "blendTrans(duration=2)";
document.images.SlideShow1
.style.fil
ter = "blendTrans(duration=cross
FadeDurati
on)";
document.images.SlideShow1
.filters.b
lendTrans.
Apply();
}
document.images.SlideShow.
src = preLoad[j].src;
document.images.SlideShow1
.src = preLoad1[j].src;
if (document.all) {
document.images.SlideShow.
filters.bl
endTrans.P
lay();
document.images.SlideShow1
.filters.b
lendTrans.
Play();
}
j = j + 1;
if (j > (p - 1)) j = 0
t = setTimeout('runSlideShow()
', slideShowSpeed);
}
</script>
</html>