Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Slideshow using VB.NET & ASP.NET

Posted on 2004-08-20
10
Medium Priority
?
1,502 Views
Last Modified: 2012-05-05
Guys,

I am new to ASP.NET & VB.NET. I have a question with regards to slideshows. How can the contents of a folder be dynamically displayed as thumbnails on a website?
 
Thanks in advance
0
Comment
Question by:wilkersons
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 5

Expert Comment

by:Gitcho
ID: 11854688
There's a number of different ways to do it.  

If you have your all your thumbnails in the same folder, you can read them from the directory into an array, and output them on your page.

If you need to dynamically resize images to thumbnails, here's a good article on it here : http://aspnet.4guysfromrolla.com/articles/081303-1.aspx


0
 
LVL 5

Expert Comment

by:Gitcho
ID: 11854749
There's an article to show you how to read images from a directory & display them in a slideshow here : http://aspnet.4guysfromrolla.com/articles/070704-1.aspx

Hope that helps ...
0
 

Author Comment

by:wilkersons
ID: 11855125
Gitcho,,

thanks. But some how i am not able to run these programs ...i need to do some reading about the above mentioned programs..

will get back soon
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 35

Expert Comment

by:YZlat
ID: 11855412
Const IMAGE_DIRECTORY As String = "images/"
        Dim pics() As String
        Dim s As String, html As String

        Dim i As Integer
        Dim objFile As IO.FileInfo

        pics = IO.Directory.GetFiles(IMAGE_DIRECTORY)

        For i = 0 To pics.Length - 1
            objFile = New IO.FileInfo(pics(i))
        Next


       
        dlPictures.DataSource = pics
        dlPictures.DataBind()
0
 

Author Comment

by:wilkersons
ID: 11855554
YZlat can you pl explain the code. How do I use this code?
0
 
LVL 5

Accepted Solution

by:
Gitcho earned 1000 total points
ID: 11856183
Do you have your webserver set up ?  

If so, save this as "index.asp" in your root directory (define your image path in the code) :

-------------------------------------------------------------------------

<%@ Import Namespace="System.IO" %>
<script runat="server" language="VB">
  Sub Page_Load(sender as Object, e as EventArgs)
    'Get list of images
    Dim dirInfo as New DirectoryInfo(Server.MapPath(""))
    Dim images() as FileInfo = FilterForImages(dirInfo.GetFiles())
   
    'Determine the current image to show
    Dim imgIndex as Integer = 0
    If Not Request.QueryString("N") is Nothing AndAlso IsNumeric(Request.QueryString("N")) then
      imgIndex = CInt(Request.QueryString("N"))
    End If
   
    currentImgTitle.Text = "You are Viewing: " & _
          Path.GetFileNameWithoutExtension(images(imgIndex).Name) & _
          " (" & imgIndex + 1 & " of " & images.Length & ")"
    currentImg.ImageUrl = Path.GetFileName(images(imgIndex).Name)
   
    If imgIndex > 0 then
      lnkPrev.NavigateUrl = "Default.aspx?N=" & imgIndex - 1
    End If
   
    If imgIndex < images.Length - 1 then
      lnkNext.NavigateUrl = "Default.aspx?N=" & imgIndex + 1
    End If
   
    dlIndex.DataSource = images
    dlIndex.DataBind()
  End Sub


  Function FilterForImages(images() as FileInfo) as FileInfo()
    Dim newImages as New ArrayList(images.Length)
   
    Dim i as Integer
    For i = 0 to images.Length - 1
      If Path.GetExtension(images(i).Name.ToLower()) = ".jpg" OrElse _
         Path.GetExtension(images(i).Name.ToLower()) = ".jpeg" OrElse _  
         Path.GetExtension(images(i).Name.ToLower()) = ".png" OrElse _
         Path.GetExtension(images(i).Name.ToLower()) = ".gif" then
        newImages.Add(images(i))
      End If
    Next
   
    Return CType(newImages.ToArray(GetType(FileInfo)), FileInfo())
  End Function
 
  Sub dlIndex_ItemDataBound(sender as Object, e as DataListItemEventArgs)
    If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem then
      'Get the Hyperlink
      Dim hl as HyperLink = CType(e.Item.FindControl("lnkPic"), HyperLink)
   
      'Set the Text and Navigation properties
      hl.Text = Path.GetFileNameWithoutExtension(DataBinder.Eval(e.Item.DataItem, "Name").ToString()) & _
             " (" & Int(DataBinder.Eval(e.Item.DataItem, "Length") / 1000) & " KB)"
      hl.NavigateUrl = "Default.aspx?N=" & e.Item.ItemIndex
    End If
  End Sub
</script>

<HTML>
<HEAD>
  <STYLE TYPE="text/css">
    body { font-family:Verdana;font-size: medium;}
    .ImageTitle { font-weight:bold; font-size:large;}
    .index {font-size: small;}
    .NavLink { background-color: yellow; font-weight: bold; }
  </STYLE>
</HEAD>
<BODY>

  <center>
    <asp:Label runat="server" id="currentImgTitle" CssClass="ImageTitle" /><br />
    <asp:Image runat="server" id="currentImg" />
    <p>
    <asp:HyperLink runat="server" CssClass="NavLink" id="lnkPrev" Text="< Previous" /> |
    <asp:HyperLink runat="server" CssClass="NavLink" id="lnkNext" Text="Next >" />
    <p>
    <asp:DataList runat="server" id="dlIndex" OnItemDataBound="dlIndex_ItemDataBound"
        RepeatColumns="3" CssClass="index">
      <ItemTemplate>
        <li><asp:HyperLink runat="server" id="lnkPic" /></li>
      </ItemTemplate>
    </asp:DataList>
  </center>

</BODY>
</HTML>


-------------------------------------------------------------------------
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 11857175
wilkersons the above code is perfect for what you are trying to accomplish, when you get familiar with this code and you prefer to give it some more dynamic look generate page like his: http://www.frozendev.com/temp/image.asp

all you have to do is give image array proper definition (image source, x-position, y-position, width and height.)
I'm sure it will look more decent then example on 4guysfromrolla...

images[0]=[];
(animate)?images[0][0]=new Image():images[0][0]=[];
(animate)?images[0][0].src="0.gif":images[0][0]="0.gif";
(animate)?images[0][1]=new Image():images[0][1]=[];
(animate)?images[0][1].src="1.gif":images[0][1]="1.gif";
(animate)?images[0][2]=new Image():images[0][2]=[];
(animate)?images[0][2].src="2.gif":images[0][2]="2.gif";

(animate)?images[0][3]=new Image():images[0][0]=[];
(animate)?images[0][3].src="3.gif":images[0][0]="3.gif";
(animate)?images[0][4]=new Image():images[0][1]=[];
(animate)?images[0][4].src="4.gif":images[0][1]="4.gif";
(animate)?images[0][5]=new Image():images[0][2]=[];
(animate)?images[0][5].src="5.gif":images[0][2]="5.gif";

(animate)?images[0][6]=new Image():images[0][6]=[];
(animate)?images[0][6].src="6.gif":images[0][6]="6.gif";
(animate)?images[0][7]=new Image():images[0][7]=[];
(animate)?images[0][7].src="7.gif":images[0][7]="7.gif";
(animate)?images[0][8]=new Image():images[0][8]=[];
(animate)?images[0][8].src="8.gif":images[0][8]="8.gif";

(animate)?images[0][9]=new Image():images[0][9]=[];
(animate)?images[0][9].src="10.gif":images[0][9]="10.gif";
(animate)?images[0][10]=new Image():images[0][10]=[];
(animate)?images[0][10].src="11.gif":images[0][10]="11.gif";


images[1]=0;        // x
images[2]=0;        // y
images[3]=200;      // w
images[4]=150;      // h
images[5]="img1";   // name
images[6]=0;        // sequence


the full example of this source code is availabe from that path I posted above this sectiom...

cheers!
 dave
0
 
LVL 35

Expert Comment

by:YZlat
ID: 11891428
wlkersons:

      ''declare your directory(where images are stored)
      Const IMAGE_DIRECTORY As String = "images/"

      ''declare an array of strings
        Dim pics() As String

        Dim s As String, html As String
        Dim i As Integer
        Dim objFile As IO.FileInfo

      ''fill an array of strings with image file names
        pics = IO.Directory.GetFiles(IMAGE_DIRECTORY)

      ''loop through the data in a array and read it into file object
        For i = 0 To pics.Length - 1
            objFile = New IO.FileInfo(pics(i))
        Next


       
        dlPictures.DataSource = pics
        dlPictures.DataBind()
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 11892508
YZat, zdarova zemliak vi gde jiviote..?
0
 

Author Comment

by:wilkersons
ID: 11897484
Thanks guys for all your answers. Got it working. I will give this one to Gitcho.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question