locked
Photo viewer with thumbnails RRS feed

  • Question

  • User1598759796 posted

    Here is simple Atlas photoviewer

    1. Main Pic
    2. Thumbnails

    I wrote it both to learn (so forgive any sloppy syntax) and because all of the available tools (eg MS Powertoys, Photoshop) take an age to prepare, this one simply looks at a photo directory and any number of sub directories.

    It's Atlas enabled to keep the postbacks speedy. 

    All suggestions/improvements truly appreciated, I hope to

    1. Atlas enable the thumbnails
    2. Add a play slideshow functionality
    3. Improve the layout (is it just me or is VWD flaky in layout, eg I center something and it refuses to acknowledge it??)  

    Note, best top keep the individual files small to speed download of the thumbnails. Clicking thumbnails will activate that pic in the main pic, but unfortunately causes loading of all thumbnails again.  Prob here seems to be I can't have Atlas controls outside the Placeholder, need to figure that out. 

    Remember to point directory at your location, also might need to add Network Service to your folder permissions.

    Hope you find it useful!

    '************

    <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>

    <%@ Register Assembly="Microsoft.Web.Atlas" Namespace="Microsoft.Web.UI.Controls"

    TagPrefix="cc3" %>

    <%@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="cc2" %>

    <%@ Register Assembly="Microsoft.Web.Atlas" Namespace="Microsoft.Web.UI" TagPrefix="cc1" %>

    <script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    Dim Di As New System.IO.DirectoryInfo("C:\Inetpub\wwwroot\Guest\images\Pics")

    Dim files() As System.IO.FileInfo

    Dim SubDir() As System.IO.DirectoryInfo = Di.GetDirectories()

     

    If IsPostBack = False Then

    For Each sdi As System.IO.DirectoryInfo In SubDir

    Me.ddnList.Items.Add(sdi.Name)

    Next

    files = My.Computer.FileSystem.GetDirectoryInfo("C:\Inetpub\wwwroot\Guest\images\Pics\" & ddnList.Text).GetFiles()

    For Each f As System.IO.FileInfo In files

    If Right$(f.Name, 4) = ".jpg" Then

    Me.ddnFiles.Items.Add(f.Name)

    End If

    Next

    End If

     

    files = My.Computer.FileSystem.GetDirectoryInfo("C:\Inetpub\wwwroot\Guest\images\Pics\" & ddnList.Text).GetFiles()

    For Each f As System.IO.FileInfo In files

    If Right$(f.Name, 4) = ".jpg" Then

     

    Dim myImage As ImageButton = New ImageButton()

    Dim j As Integer

    j = j + 1

    'Set the label's Text and ID properties.

    myImage.ID = CStr(j)

    myImage.ImageUrl = "~\Guest\images\Pics\" & ddnList.Text & "\" & f.Name

    myImage.Height = 40

    myImage.Width = 50

    myImage.ToolTip = f.Name

    'myImage.OnCommand = "ImageButton_Command"

    myImage.CommandName = "NA"

    myImage.CommandArgument = f.Name

    myImage.AlternateText = f.Name

    AddHandler myImage.Command, AddressOf Me.ImageButton_Command

    PlaceHolder1.Controls.Add(myImage)

    'Add a spacer in the form of an HTML <BR> element

    Dim spacer As LiteralControl = New LiteralControl(" ")

    PlaceHolder1.Controls.Add(spacer)

    End If

    Next

    End Sub

     

    Protected Sub ddnFiles_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

    imgMain.ImageUrl = "~/Guest/images/Pics/" & ddnList.Text & "/" & ddnFiles.Text

    ' hypPic.NavigateUrl = "~/Guest/Slideshows/" & ddnList.Text & "/" & ddnFiles.Text

     

    End Sub

    Protected Sub ddnList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

    Dim files() As System.IO.FileInfo

     

    ddnFiles.Items.Clear()

     

    files = My.Computer.FileSystem.GetDirectoryInfo("C:\Inetpub\wwwroot\Guest\images\Pics\" & ddnList.Text).GetFiles()

    For Each f As System.IO.FileInfo In files

    If Right$(f.Name, 4) = ".jpg" Then

    Me.ddnFiles.Items.Add(f.Name)

    End If

    Next

    imgMain.ImageUrl = "~/Guest/images/Pics/" & ddnList.Text & "/" & ddnFiles.Text

    End Sub

    Sub ImageButton_Command(ByVal sender As Object, ByVal e As CommandEventArgs)

    imgMain.ImageUrl = "~/Guest/images/Pics/" & ddnList.Text & "/" & e.CommandArgument

    'imgMain.Text = e.CommandArgument

    ddnFiles.Text = e.CommandArgument

    End Sub

    </script>

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <script language="javascript" type="text/javascript">

    <!--

    function TABLE1_onclick() {

    }

    // -->

    </script>

    <asp:DropDownList ID="ddnList" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddnList_SelectedIndexChanged">

    </asp:DropDownList><cc1:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True">

    </cc1:ScriptManager>

    <cc1:UpdatePanel ID="UpdatePanel1" runat="server">

    <ContentTemplate>

    <asp:DropDownList ID="ddnFiles" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddnFiles_SelectedIndexChanged">

    </asp:DropDownList><div style="text-align: center">

    </div>

    <asp:ImageButton ID="imgMain" runat="server" Height="402px" ImageUrl="~/Guest/images/Pics/Bell Island/Bell Island (1).jpg" Width="578px" />

    </ContentTemplate>

    </cc1:UpdatePanel>

    <hr />

    &nbsp;<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>

     

     

     

    </asp:Content>

     

     

     

    Monday, October 9, 2006 8:30 PM

All replies

  • User396509987 posted

    hi MikeyBoyd !!! happy new year

    i would like to give u a complete image galley to learn from

    <a href="http://www.inputoutputinfo.com/dotnet/cSharp/Web-Development/ASP.NET/ASPNet-Simple-Image-Gallery"> Code for Image gallery </a> 

    regards Awais
    Friday, January 2, 2009 2:43 AM