Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   ASP.NET (http://www.programmingforums.org/forum35.html)
-   -   Slide Show (http://www.programmingforums.org/showthread.php?t=15483)

King Mar 25th, 2008 10:15 PM

Slide Show
 
I am doing a website in ASP.Net and I need to implement a slide show and I have a few questions.

I was able to implement one in JavaScript fairly easily, but I need to be able to load all the images from a folder without knowing how many images there will be and I do not think that is possible with JavaScript. If there is a way to be able to read/display all the images from a folder (without knowing all the files names) with JavaScript please let me know ;).

If the JavaScript way is not possible I will do it server-side. If I do it server-side is there a way to have it automatically switch the picture after X amount of time without an AJAX timer or anything fancy like that?

I may just end up using the AJAX slide show control. It is a fairly simple website and did not want to use too much server-side code or AJAX stuff. Thanks for any input on this.

Ghost Mar 26th, 2008 6:01 AM

Re: Slide Show
 
Please post java-script

Ooble Mar 26th, 2008 6:32 AM

Re: Slide Show
 
I would use ASP.NET to tell the JavaScript what the file names are. Not sure about ASP, but this is how I'd do it in PHP:
:

  1. <?php
  2. $imageDir = 'images/';
  3. $imagePaths = scandir($imageDir);
  4. echo 'var imagePaths = Array ("' . implode('", "', $imagePaths) . '")';
  5. ?>


Ghost Mar 26th, 2008 3:31 PM

Re: Slide Show
 
Here are a few places to check out.

http://www.asp.net/AJAX/AjaxControlT...SlideShow.aspx

http://aspnet.4guysfromrolla.com/articles/070704-1.aspx

http://www.codeproject.com/KB/ajax/ASPNETSlideShow.aspx

grimpirate Mar 26th, 2008 5:21 PM

Re: Slide Show
 
Don't know if this will be of use to you, as I just happened over it and didn't really inspect it too closely:
http://www.wikicodia.com/wiki/JavaSc...ory_files_list
http://www.codeproject.com/KB/script..._in_files.aspx

grimpirate Mar 26th, 2008 5:51 PM

Re: Slide Show
 
Alright I tested the following code on my local Apache server:
:

<script type="text/javascript">
function httpGetText(aURL) {
  var req = new XMLHttpRequest();
  req.open('GET', aURL, false);
  req.send(null);
  return req.responseText;
}
document.write(httpGetText('http://localhost/somedir/'));
</script>

I created a temporary directory called 'somedir' and it worked. However, if I added an index.htm file into the directory it just returned that file rather than the list of files. Basically, that means that directory scans can only be performed on server's whose default behavior is to return the list of files within that directory; provided of course there isn't an index page or that it doesn't return a 404 or other such error code.

King Apr 2nd, 2008 3:35 PM

Re: Slide Show
 
Thanks for the info guys. I have chosen to use the Ajax Slide Show control.

I have one more question. In ASP, what is the best way to get a list of files from a directory? This is how I am doing it currently:
:

string directory = "c:/Inetpub/wwwroot/MyWebsite/test_images/";
DirectoryInfo di = new DirectoryInfo(directory);
foreach (FileInfo oFile in di.GetFiles())
{
        string fileName = oFile.Namel
        // ...
}

The problem with this is that it is relying on the filesystem and I do not know how the hosting provider will have their server setup. Is there a way where I can search the IIS virtual directory and just pass in "~/test_images" as the directory string?

kruptof Apr 2nd, 2008 5:03 PM

Re: Slide Show
 
Try getting the current working directory and go from there, not sure of exact syntax but I think it goes something like this:
:

Directory.GetCurrentDirectory()

Jimbo Apr 2nd, 2008 8:39 PM

Re: Slide Show
 
You can probably use Server.MapPath("~/Some/Path") :)

King Apr 7th, 2008 7:27 AM

Re: Slide Show
 
kruptof / Jimbo... both of those worked :)

Server.MapPath("~/Some/Path") did it in one less step though. Thanks guys. I now have the slide show running as desired.


All times are GMT -5. The time now is 8:22 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC