ASP.NET - slideshow automatic update - Asked By kiran Kumar on 13-Mar-12 02:37 AM

Earn up to 10 extra points for answering this tough question.

  in my asp web form default2.aspx, i have placed one image control and attached the extender Slide show extender control to the image control

 I have placed one script manager also

 I have placed one folder in my website with the name "images"

 The images folder consists of the images which i have uploaded using FileUploading control which i have placed in Default3.aspx 

 For that i wrote the code and the images are uploading in to images folder using File Upload

 Now,  i want to show those images which the images folder consists of and after it get updated with new images also.

And the images will be displayed in slide show.  How to do this??
[)ia6l0 iii replied to kiran Kumar on 13-Mar-12 09:22 PM
There is no speical coding required to do this, if you are already reading the images from a folder. It will automatically get updated. 

If you have a slideshowextender that has the SlideShowService method set to one of the webmethods, like following, then you need to ensure that you are reading the images from the very same folder and building the slides.
<ajaxToolkit:SlideShowExtender ID="SlideShowExtender1" runat="server"  TargetControlID="Image1" SlideShowServiceMethod="GetSlidesFromFolder" /

And perhaps, you have the GetSlidesFromFolder definition as follows:
public static AjaxControlToolkit.Slide[] GetSlidesFromFolder()
//Do a server.mappath to the images folder and find out how many images you have.
string[] images = System.IO.Directory.GetFiles(Server.MapPath("Images"));
//Based on the image count, create the slide array.
AjaxControlToolkit.Slide[] slides = new AjaxControlToolkit.Slide[images.length];

//Loop thru the images and create slides
for (int counter = 0; counter < images.Length; counter++)
//Use System.IO.File.GetFilename to get the file name.
slides[counter] = new AjaxControlToolkit.Slide("images/" + System.IO.File.GetFileName(file));
//return the images as slides.
return slides;

Hope this helps.

kiran Kumar replied to [)ia6l0 iii on 14-Mar-12 01:38 AM
it is not working yar....
[)ia6l0 iii replied to kiran Kumar on 14-Mar-12 01:44 AM
What is "yar"?

And be specific when you say "it is not working". Let all know - what is the actual problem?

A problem well stated is a problem half solved. - Charles Kettering
kiran Kumar replied to [)ia6l0 iii on 14-Mar-12 01:49 AM
i wrote the code as you said.. it is showing error messages:

 System.IO.File does not contain a definition for 'GetFileName'


 System.IO.File is a type but is used like a 'variable'

[)ia6l0 iii replied to kiran Kumar on 14-Mar-12 02:07 AM
Good. You have moved forward.

Pardon me for the mistake on the code. Get into a habit of reading MSDN and debugging your code. No one is going to do that for you.

The Filename method was not on the System.IO.File. It is on the Path class.

Please read the documentation link posted above. It shows you the exact example of how to use this method.

And I have another advice for you. 
Don't "develop by Google" unless you know what the code is doing line by line.

Somesh Yadav replied to kiran Kumar on 14-Mar-12 07:18 AM
Hi kiran follow the below steps:-
Step 1 - On the top of your aspx file you have to add reference to the Ajax Control Toolkit:
view plaincopy to clipboardprint?

    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>  

Step 2 - Now you have to add Toolkit Script Manager, in order to do so add following code within <form> element:
view plaincopy to clipboardprint?

    <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">  

Step 3 - Then you should add to your page Image control where all your photos will be displayed. Under it place 3 buttons (for going forward, backward and for play/pause). Text for play/pause button will be changed by the extender itself depending on the current state of the slide show. You can add all items manually, dragging them from the toolbox or you can just paste following code to your aspx file.
view plaincopy to clipboardprint?

    <asp:Image ID="Image1" runat="server" />  
    <div style="text-align:center">  
    <asp:Button ID="Button1" Text="<<<" runat="server" />  
    <asp:Button ID="Button2" runat="server" />  
    <asp:Button ID="Button3" Text=">>>" runat="server" />  

Step 4 - Now we'll add SlideShow extender to our code. Firstly we'll have to specify in TargetControlID id of the control where the images will be displayed. SlideShowServiceMethod sets the method which will be used to fetch images and SlideShowServicePath sets a path to a webservice. Then you have to provide IDs of the buttons. PlayButtonText and StopButtonText contain text that will be displayed on a play/pause button when the slide show is running or stopped. Finally AutoPlay option starts slide show automatically when the page is opened.
view plaincopy to clipboardprint?

    <ajaxToolkit:SlideShowExtender ID="SlideShowExtender1" runat="server"  

Step 5 - Creating a webservice. Right-click on your project name in Solution Explorer and select Add New Item. Then find Web Service on the list and click Add button. This will add a new asmx file to your project. Remember to uncomment following line to allow Web Service to be called from script:
view plaincopy to clipboardprint?


Now all you have to do is add following method to your new Web Service:
view plaincopy to clipboardprint?

    public AjaxControlToolkit.Slide[] GetSlides()  
    AjaxControlToolkit.Slide[] slides = new AjaxControlToolkit.Slide[3];  
    slides[0] = new AjaxControlToolkit.Slide("1.jpg", "Image1", "house");  
    slides[1] = new AjaxControlToolkit.Slide("2.jpg", "Image2", "seaside");  
    slides[2] = new AjaxControlToolkit.Slide("3.jpg", "Image3", "car");  
    return (slides);  

Your slide show is ready! Of course you can add more photos to it.