ASP.NET - photo albam  ASP.NET - photo albam

Asked By Bala Marish
16-May-11 12:33 AM


how to create photo albam using asp.net
  Vickey F replied to Bala Marish
16-May-11 12:34 AM

Have a look at the following sample projects:

  • This article explains an ASP.NET application to view and share photos online. http://www.codeproject.com/KB/applications/NetPix.aspx 
  • Shows how to store images in SQL Database Image Storage & create Thumnails easiliy from http://www.codeproject.com/KB/web-image/EasyThumbs.aspx
  • How to upload files to Web pages in ASP.NET? How to read an image from a database using ADO.NET and display it in a Web page? http://www.codeproject.com/KB/web-image/PicManager.aspx
  • Provide a very simple set of instructions for creating your own media gallery and loading your images from SQL Server 2005 http://www.codeproject.com/KB/web-image/CPImageGallery.aspx
  Sahil Kumar replied to Bala Marish
16-May-11 12:36 AM
HI,

There are lots of nice tutorial on internet for create photo album, it have source code attached with these tutorials. Out of all of that few best one are these, just help your self

http://weblogs.asp.net/bleroy/archive/2005/09/08/a-simple-asp-net-photo-album.aspx
http://www.codedigest.com/Articles/ASPNET/232_Picasa_Style_Photo_Album_Using_ListView_Control_in_ASPNet_35.aspx
http://www.codeproject.com/KB/web-image/NickPhotoBrowser.aspx

Please let me know if you have any issue. Hope this help you.
  James H replied to Bala Marish
16-May-11 12:41 AM
Hi please use this code snippet 
<asp:ListView ID="ListView1" runat="server" GroupItemCount="3">
        <LayoutTemplate>
          <asp:PlaceHolder ID="groupPlaceholder" runat="server" />
        </LayoutTemplate>
        <GroupTemplate>
          <div>
            <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
          </div>
        </GroupTemplate>
        <ItemTemplate>
          <asp:Label ID="lblConID" runat="server" Text='<%# Eval("CNTIMG_ID") %>' Visible="false"></asp:Label>
          <asp:CheckBox ID="chkdel" runat="server" AutoPostBack="true" />
          <asp:Image ID="ImgPic" runat="server" AlternateText='<%# Eval("CNTIMG_CONTAINER_IMAGE_PATH") %>'
            ImageUrl='<%# "~/ContainerImages/" + DataBinder.Eval(Container.DataItem, "CNTIMG_CONTAINER_IMAGE_PATH") %>'
            Width="150px" Height="120px" />
          <%--  <asp:ImageButton ID="imgDel" runat="server" ImageUrl="~/Images/delete_btn.gif" />--%>
        </ItemTemplate>
        <EmptyItemTemplate>
        </EmptyItemTemplate>
      </asp:ListView>
On Page Load

Image img = (Image)ListView1.FindControl("ImgPic");
 
        ListView1.DataSource = ds.Tables[4];
 
        ListView1.DataBind();

 You can refer this link where you can get the way you can implement this module ...you can get source code also ....

 http://www.codedigest.com/Articles/ASPNET/232_Picasa_Style_Photo_Album_Using_ListView_Control_in_ASPNet_35.aspx

http://www.codeproject.com/KB/web-image/NickPhotoBrowser.aspx

Hope this will help you :-)

  Riley K replied to Bala Marish
16-May-11 12:47 AM

Follow these below steps


Understanding DataBase Design


Before moving to the actual implementation, we will first see the database design which stores the album information to understand the implementation better.  Refer the below database diagram,

The database contains 2 tables,

1.    Album – Stores information’s about album. DefaultPhotID column stores ID of the photo that is set as album cover.

2.    PhotAlbum – It contains all the information about albums. The column Photo will store location of the photo where it is uploaded.

You can increase the column size as per your need.

 

Photo Album - CodeDigest.Com,DB.png

In coming sections, we will see how we can implement this with ListView control.

 

Creating Albums List

In Album List Page, we will display 3 albums in a row in Tiled format i.e. to repeat the display of items horizontally, Refer Figure 1. To create a new Album, a “Create New Album” link will be displayed at the end of the ListView control. This link will be automatically moved to the last column of the ListView control whenever a new Album is added. We will see how this can be implemented with ListView control.

To display data in ListView control, we have to first define the mandatory templates, Layout Template and Item Template.  Read my previous article - http://www.codedigest.com/Articles/ASPNET/91_ListView_Control_in_ASPNet_35.aspx to gain more knowledge on this.

Additionally, we will use Group Template to group the data in tiled format. We can restrict the number of items in a row by using a property called GroupItemCount.

To display “Create New Album” link, we can use another ListView template called InsertItemTemplate. The content in InsertItemTemplate will be displayed to insert a new item in the ListView.  We can set the property called InsertItemPosition to dictate where we can display the InsertItemTemplate. In our case, it is LastItem.

 

So, our final ListView control code will look like,

 

<asp:ListView ID="lvAlbums" runat="server"

        DataSourceID="SqlDataSource1" GroupItemCount="3"

        InsertItemPosition="LastItem">       

        <LayoutTemplate>         

            <table border="1">

             <tr ID="groupPlaceholder" runat="server">

             </tr>

            </table>            

        </LayoutTemplate>                       

        <GroupTemplate>

            <tr>

              <td ID="itemPlaceholder" runat="server">

              </td>

            </tr>

       </GroupTemplate>      

       <ItemTemplate>

            <td id="Td3" width="150px" height="150px" align="center" style="background-color: #e8e8e8;color: #333333;">

            <asp:HiddenField ID="hfPhotoID" runat="server" Value='<%# Eval("DefaultPhotID") %>' />

            <a href='<%# "Photos.aspx?AlbumID="+Eval("AlbumID") %>'>

            <asp:Image CssClass="Timg" runat="server" ID="imPhoto" ImageUrl='<%# "ThumbNail.ashx?ImURL="+Eval("Photo") %>' />

            </a>

            <br />           

            <b><asp:Label ID="lblAlbumName" runat="server" Text='<%# Eval("AlbumName") %>'></asp:Label>   </b>

            </td>         

          </ItemTemplate>

          

          <InsertItemTemplate>

          <td id="Td3" width="150px" height="150px" runat="server" align="center" style="background-color: #e8e8e8;color: #333333;">

          <a href="CreateAlbum.aspx">           

            Create New Album

          </a>

          </td>       

          </InsertItemTemplate>      

        </asp:ListView>

 

      <asp:SqlDataSource ID="SqlDataSource1" runat="server"

        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

        SelectCommand="SELECT Album.AlbumID, Album.DefaultPhotID, Album.AlbumName, PhotAlbum.Photo FROM Album INNER JOIN PhotAlbum ON Album.DefaultPhotID = PhotAlbum.PhotoID">

      </asp:SqlDataSource>

 

In the above code, I have used GroupItemCount as 3. Increase this value to display more number of Albums in a row.  I have used SqlDataSource control to bind the data from database.

 

Since, the album cover should be the one of the photo(DefaultPhotID column of Album table) uploaded in the album, we should display its thumbnail version as its album cover. To do this, we will use an HttpHandler[ThumbNail.ashx] which will convert the full image to Thumbnail image.

Below, you can find the HttpHanlder implementation that generates the thumbnail image(100x100) from the original image.

 

<%@ WebHandler Language="C#" Class="ThumbNail" %>

 

using System;

using System.Web;

using System.Drawing;

using System.IO;

 

public class ThumbNail : IHttpHandler {

   

    public void ProcessRequest (HttpContext context) {

      string imageurl = context.Request.QueryString["ImURL"];

      string str = context.Server.MapPath(".") + imageurl;

      Bitmap bmp = new Bitmap(str);

      System.Drawing.Image img = bmp.GetThumbnailImage(100, 100, null, IntPtr.Zero);

      MemoryStream ms = new MemoryStream();

      img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

      byte[] bmpBytes = ms.GetBuffer();

      img.Dispose();

      ms.Close();

 

      context.Response.BinaryWrite(bmpBytes);

      context.Response.End();   

    }

 

    public bool IsReusable {

      get {

        return false;

      }

    }

 

}

 

Next, clicking “Create New Album” link will take us to CreateAlbum.aspx page to create new album. Once the album is created, this will further take to photo uploading page (ImageUpload.aspx) to upload images for an album. Refer the below figures,

CreateAlbum.aspx

 Photo Album - CodeDigest.Com,CreateAlbum.aspx

ImageUpload.aspx

Photo Album - CodeDigest.Com,ImageUpload.aspx 

I am not going to discuss about the implementation of these pages as this is not in the scope of the article. You can download the source attached with this article to see it in action. 

 

At last, when a user clicks an Album, he or she will be re-directed to page (photos.aspx) where we should display the list of photos that is uploaded under the album in thumbnail view.


Displaying photos in Thumbnail View

In photos.aspx page, we will accept the AlbumId through the QueryString parameter and populate the ListView control.  Again, we will use GroupTemplate to display 3 photos per row. Refer the Figure 2. In Figure 2, the list of thumbnail photos(content in right) are rendered by the ListView control while content on the left side which displays Album information is handled separately.

 

 To display the thumbnail view of every photo, we will use the same HttpHandler [ThumbNail.ashx] used in Albums page. You can consider saving a thumbnail version of every photo while uploading to improve performance. In this approach, every time when the user views the album it will generate the equivalent thumbnail image which we can really prevent if we do the thumbnail conversion when the user uploading the actual image.  Refer the below link to do this,

http://www.codedigest.com/CodeDigest/38-Upload-image-to-file-system-and-create-thumbnail-image-on-the-fly-in-C--and-ASP-Net.aspx

 

Finally, ListView control will look like,

<asp:ListView ID="lvPhotos" runat="server" DataKeyNames="AlbumID"

        DataSourceID="SqlDataSource1" GroupItemCount="3">       

        <LayoutTemplate>        

           <table ID="groupPlaceholderContainer" runat="server" border="0" cellpadding="0" cellspacing="0">

               <tr ID="groupPlaceholder" runat="server">

             </tr>

           </table>             

        </LayoutTemplate>             

        <GroupTemplate>

            <tr ID="itemPlaceholderContainer" runat="server">

              <td ID="itemPlaceholder" runat="server">

              </td>

            </tr>

          </GroupTemplate>      

          <ItemTemplate>

            <td runat="server" align="center" style="background-color: #e8e8e8;color: #333333;">           

            <a href='<%# "PhotoViewer.aspx?PhotoID="+Eval("PhotoID")+"&AlbumID="+ Eval("AlbumID") %>'>

            <asp:Image CssClass="Timg" runat="server" ID="imPhoto" ImageUrl='<%# "ThumbNail.ashx?ImURL="+Eval("Photo") %>' />

            </a>

            </td>         

          </ItemTemplate>      

        </asp:ListView>

 

<asp:SqlDataSource ID="SqlDataSource1" runat="server"

          ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

        SelectCommand="SELECT [PhotoID], [Photo], [PhotoName], [AlbumID] FROM [PhotAlbum] WHERE ([AlbumID] = @AlbumID) ORDER By [PhotoID] ASC"

        onselected="SqlDataSource1_Selected">

          <SelectParameters>

            <asp:QueryStringParameter DefaultValue="1" Name="AlbumID"

              QueryStringField="AlbumID" Type="Int32" />

          </SelectParameters>

        </asp:SqlDataSource>

 

Again, I have used SqlDataSource control to bind the data from database. 

To view the full image, users have to click any of the thumbnail images which will load the full image with next and previous button. Next section will help you to do this.

 

Viewing Full Image

Once the user clicks any of thumbnail images we will load the full image in a ListView control(Refer PhotoViewer.aspx in our sample) by accepting AlbumId and PhotoID as query string parameter.  Refer Figure 3 for better understanding. We will also display next and previous button to navigate between the photos in that album.  Unlike the other 2 pages, we will bind the data using our code.

 

In this scenario, we will display one image at a time in ListView control as seen the Figure 3. We will again use GroupTemplate to display the images in ListView.

Note

We can also do this without using GroupTemplate. Using GroupTemplate we can increase the number photos displayed at a time using GroupItemCount property.

 

Next and Previous button is displayed through the DataPager control. Read my article - http://www.codedigest.com/Articles/ASPNET/100_Paging_in_ListView_in_ASPNet_35.aspx to know more about DataPager and Paging in ListView control.

 

So, our ListView control will look like,

<table>

    <tr>

    <td>

      <asp:ListView ID="lvPhotoViewer" runat="server" GroupItemCount="1">

     <LayoutTemplate>         

       <table ID="groupPlaceholderContainer" runat="server" border="1">                

          <tr ID="groupPlaceholder" runat="server">

          </tr>

       </table>            

     </LayoutTemplate>

        

     <ItemTemplate>

       <td id="Td4" align="center" style="background-color: #eeeeee;">

            <asp:Image runat="server" ID="imPhoto" Height="450px" Width="450px" ImageUrl='<%# "~"+Eval("Photo") %>' />

            <br />

            <asp:Label ID="DefaultPhotIDLabel" runat="server"

                Text='<%# Eval("PhotoName") %>' />

       </td>

      </ItemTemplate>

  

     <GroupTemplate>

        <tr ID="itemPlaceholderContainer" runat="server">

           <td ID="itemPlaceholder" runat="server">

           </td>

        </tr>

      </GroupTemplate>

      </asp:ListView>

    </td>

    </tr>

    <tr>

    <td align="center">

      <asp:DataPager ID="DataPager1" runat="server"

      PagedControlID="lvPhotoViewer" PageSize="1"

      onprerender="DataPager1_PreRender">

      <Fields>

        <asp:NextPreviousPagerField ButtonType="Link"

        PreviousPageText="<< " NextPageText=" >>" />

     </Fields>

      </asp:DataPager>

    </td>

    </tr>

    </table>   

 

CodeBehind

protected void Page_Load(object sender, EventArgs e)

    {

      if (!Page.IsPostBack)

      {

        string photoID = Request.QueryString["PhotoID"];

        string albumID = Request.QueryString["AlbumID"];

        ViewState["hfAlbumID"] = albumID;

        //Get Page number by passing photo id

        int index = GetPageNumber(int.Parse(photoID), int.Parse(albumID));

        DataPager1.SetPageProperties(index, 1, true);     

      }

    }

    /// <summary>

    /// Since the pagesize is 1 the row number can be taken as page number

    /// </summary>

    /// <param name="PhotoID"></param>

    /// <param name="AlbumID"></param>

    /// <returns></returns>

public int GetPageNumber(int PhotoID,int AlbumID)

    {

      SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

      con.Open();

      SqlCommand com = new SqlCommand("SELECT PageNumber FROM (SELECT row_number() Over (order by photoid asc) AS PageNumber,photoid,Albumid FROM PhotAlbum where Albumid=" + AlbumID.ToString() + ") As Photos where photoid=" + PhotoID.ToString() + " and Albumid=" + AlbumID.ToString(), con);

      SqlDataReader dr = com.ExecuteReader();

      int pageno = 1;

      if (dr.Read())

      {

        pageno = int.Parse(dr["PageNumber"].ToString());

      }

      dr.Close();

      con.Close();

      return (pageno - 1);    

    }

    public DataTable GetPhoto(string query)

    {

      SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

      SqlDataAdapter ada = new SqlDataAdapter(query, con);

      DataTable dtEmp = new DataTable();

      ada.Fill(dtEmp);

      return dtEmp;

    }  

    protected void DataPager1_PreRender(object sender, EventArgs e)

    {

      lvPhotoViewer.DataSource = GetPhoto("Select * from PhotAlbum where AlbumID = " + ViewState["hfAlbumID"].ToString());

      lvPhotoViewer.DataBind();

    }   

 

Since, we are displaying one image at a time i.e. PageSize is 1, the page number and Row number got from SqlServer 2005 will be same. Hence, GetPageNumber() method will return the Row_Number() of the Thumbnail photo that is clicked to reach this page and it can be used to bind the particular page in ListView control.

Note

Row_Number() will work in Sql Server 2005 and above only. I have used inline query to bind the data from database. You can consider using stored procedures for better performance and also it prevents SQL injection attack.

 

  Anoop S replied to Bala Marish
16-May-11 12:48 AM
better to create with Ajax , A simple FREE tool called Ajax Photo Gallery allows you to create a custom image gallery with a cool slide show of your most interesting photoson your website or blog in a few easy steps. Just drag&drop your photos into Ajax Photo Gallery window, select the style of thumbnails and the overlay window and add the HTML embed code on your website or blog.
No javascript,css,html coding, no image editing, just a click to get your gallery ready. A few clicks and you'll see a stylish photo gallery with beautifull lightbox and zoom effects on your own website or blog!here is one good example for how to create photo gallery using Ajax
http://ajaxphotogallery.com/asp-net-photo-gallery.html
  S replied to Bala Marish
16-May-11 12:48 AM

A while ago, I spent considerable time scouring the net, looking for my perfect photo gallery. I tried the different solutions already available on the net, but for one reason or another, I was unable to fit them to my needs.

  • I needed a photo gallery that "just works." All you need to do is plunk a couple of pictures in a folder and that's that.
  • The gallery also needed to be aesthetically pleasing.
  • The gallery should be easy to use.

I decided to give it a try myself. Within a weekend, I believe, I created something that fit all my needs. Hopefully it will fit yours, too.

Step 1

The first step is to create a "New Website..." project in Visual Studio .NET 2005. After the creation is complete, you will have a Default.aspx file and a web.config file. Create a folder PicStore in the root. This is the folder that will hold your galleries.

Inside the PicStore folder, create a Default sub-folder. We are creating this to denote the default set of galleries. This is for the future, when I plan to expand the application to include the galleries of my friends. They will reside in other folders, but the Default set of galleries will be loaded when the application is first browsed by the user.

Inside the Default folder, create your galleries. I suggest, for the sake of the article, creating Photogallery 1, Photogallery 2, etc. In each of these galleries, create a pics folder. This folder will hold your pictures.

Note:

  1. Only JPG file format is accepted.
  2. Photos have to be named in the pattern 001.JPG, 002.JPG, 003.JPG, ...
  3. If you want to include a title for any photo, rename it to the pattern 00X~Title_With_Underscores_For_Spaces.JPG, where X is the number of the photo.

The gallery has been designed to neatly show pictures that are a maximum of 750 pixels wide. You can, of course, put bigger or smaller pictures, but you then need to adjust the background accordingly. I would suggest to keep all the pictures of the same maximum width. You could use the free tool http://www.irfanview.com/ to batch format all your images to a particular size. There is an option in "Batch conversion> Advanced options" to set the long side of all images to a particular size. This fitted my requirements perfectly.

Optionally, you could also create a sibling folder thumbs to the pics folder, if you want the users to be able to see the thumbnails of your pictures instead of the image names in the navigation. I would suggest that the long side of your thumbnails should be limited to 100 pixels.

There are some images like arrow2.gif, bg.gif, etc. provided in my sample code. You could download these and put them in the appropriate folders in the project root, or alternatively, remove references to these from the code.

The final thing that we have to do is add the keys PicRootPath and PicRootDefaultPath to the web.config, as follows:

Collapse
<appSettings>
    <add key="PicRootPath" value="~/PICStore/"/>
    <add key="PicRootDefaultPath" value="~/PicStore/Default/" />
</appSettings>

That was the preparation of the project. Now, we will add code for the gallery.

Step 2

Now, we create an App_Code folder in the project, if it doesn't exist already. Inside this, we will create a class ContentInfoLoader. This class will be responsible for loading information about the galleries and the photos for our application. The constructor of our class will load the root path of the galleries and the default set of galleries. Following is the code for this:

Collapse
Configuration rootWebConfig = 
    WebConfigurationManager.OpenWebConfiguration("~/");
if(0<rootWebConfig.AppSettings.Settings.Count)
{
    KeyValueConfigurationElement picRootElement = 
        rootWebConfig.AppSettings.Settings["PicRootPath"];
    if(null!=picRootElement)
    {
        _picRootPath=picRootElement.Value;
    }

    picRootElement = rootWebConfig.AppSettings.Settings["PicRootDefaultPath"];
    if (null != picRootElement)
    {
        _picRootDefaultPath = picRootElement.Value;
    }
}

The paths are stored in private variables which can be accessed via the readonly properties. Now we create a simple method to get the list of galleries available in our set. Following is the code for the same:

Collapse
public string[] GetGalleryPaths(string picRootRealPath) 
{
    if (Directory.Exists(picRootRealPath))
    {
        return Directory.GetDirectories(picRootRealPath);
    }
    else
    {
        return null;
    }
}

As you can see, the method takes the path for the root of the pictures (it could be the default one or any other) and it returns a string array containing the gallery paths. Note that these are physical paths. We need to create another method to get a list of photos in each of the galleries currently selected. The following is the code that does this:

Collapse
public string[] GetPhotoList(string galleryName, string picRootRealPath)
{
    string galleryPath=picRootRealPath + "\\" + galleryName + "\\pics";
    if (Directory.Exists(galleryPath))
    {
        return Directory.GetFiles(galleryPath,"*.JPG");
    }
    else
    {
        return null;
    }
}

Note that this method takes the name of the gallery and the root path. It returns a list of photos with their physical paths.

Step 3

Now we create a master page to go with our gallery application page.

First, I would suggest deleting the Default.aspx file that was automatically created by the project. Next, right click on the project in the Solution Explorer and click on "Add New Item..." Choose "Master Page" and name it SuperMasterPage.master. Add the following JavaScript code to your master page, just after the body tag:

Collapse
<script type="text/javascript">

    var offsetfromcursorX=12 //Customize x offset of tooltip

    var offsetfromcursorY=10 //Customize y offset of tooltip


    //Customize x offset of tooltip DIV relative to pointer image

    var offsetdivfrompointerX=10
    //Customize y offset of tooltip DIV relative 

    //to pointer image. Tip: Set it to 

    //(height_of_pointer_image-1).

    var offsetdivfrompointerY=7

    //write out tooltip DIV

    document.write('<div id="dhtmltooltip"></div>')
    //write out pointer image

    document.write('<img id="dhtmlpointer" ' + 
        'src="http://www.codeproject.com/SourceCode/images/arrow2.gif">')

    var ie=document.all
    var ns6=document.getElementById && !document.all
    var enabletip=false
    if (ie||ns6)
    var tipobj=document.all? document.all["dhtmltooltip"] : 
        document.getElementById? 
        document.getElementById("dhtmltooltip") : ""

    var pointerobj=document.all? document.all["dhtmlpointer"] : 
        document.getElementById? 
        document.getElementById("dhtmlpointer") : ""

    function ietruebody()
    {
        return (document.compatMode && document.compatMode!="BackCompat")? 
            document.documentElement : document.body
    }

    function ddrivetip(thetext, thewidth, thecolor)
    {
        if (ns6||ie)
        {
            if (typeof thewidth!="undefined")
                tipobj.style.width=thewidth+"px"
            if (typeof thecolor!="undefined" && thecolor!="")
                tipobj.style.backgroundColor=thecolor
                tipobj.innerHTML=thetext
                enabletip=true
                return false
        }
    }

    function positiontip(e)
    {
        if (enabletip)
        {
            var nondefaultpos=false
            var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
            var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
            //Find out how close the mouse is to the corner of the window

            var winwidth=ie&&!window.opera? ietruebody().clientWidth : 
                window.innerWidth-20
            var winheight=ie&&!window.opera? 
                ietruebody().clientHeight : window.innerHeight-20
            var rightedge=ie&&!window.opera? 
                winwidth-event.clientX-offsetfromcursorX : 
                winwidth-e.clientX-offsetfromcursorX
            var bottomedge=ie&&!window.opera? 
                winheight-event.clientY-offsetfromcursorY : 
                winheight-e.clientY-offsetfromcursorY
            var leftedge=(offsetfromcursorX<0)? 
                offsetfromcursorX*(-1) : -1000

            //if the horizontal distance isn't enough to 

            //accomodate the width of the context menu

            if (rightedge<tipobj.offsetWidth)
            {
                //move the horizontal position of 

                //the menu to the left by it's width

                tipobj.style.left=curX-tipobj.offsetWidth+"px"
                nondefaultpos=true
            }
            else if (curX<leftedge)
                tipobj.style.left="5px"
            else
            {
                //position the horizontal position of 

                //the menu where the mouse is positioned

                tipobj.style.left=curX+offsetfromcursorX-
                    offsetdivfrompointerX+"px"
                pointerobj.style.left=curX+offsetfromcursorX+"px"
            }

            //same concept with the vertical position

            if (bottomedge<tipobj.offsetHeight)
            {
                tipobj.style.top=curY-tipobj.offsetHeight-
                    offsetfromcursorY+"px"
                nondefaultpos=true
            }
            else
            {
                tipobj.style.top=curY+offsetfromcursorY+
                    offsetdivfrompointerY+"px"
                pointerobj.style.top=curY+offsetfromcursorY+"px"
            }
            tipobj.style.visibility="visible"
            if (!nondefaultpos)
                pointerobj.style.visibility="visible"
            else
                pointerobj.style.visibility="hidden"
        }
    }

    function hideddrivetip()
    {
        if (ns6||ie)
        {
            enabletip=false
            tipobj.style.visibility="hidden"
            pointerobj.style.visibility="hidden"
            tipobj.style.left="-1000px"
            tipobj.style.backgroundColor=''
            tipobj.style.width=''
        }
    }

    document.onmousemove=positiontip

</script>

This JavaScript code will be used to display a tooltip for showing the gallery names and thumbnails.

Note: Wherever you see "/SourceCode/" in the code, please replace it with whatever is the "virtual directory" in which you have created your application. If you have created it in the root of your machine website, remove the /SourceCode/ where necessary.

Step 4

Now we need to create our actual gallery display page so that it can use the class that we created above. Right click on your project and click on "Add New Item..." Choose a "Web Form" and make sure that the checkboxes "Place code in a separate file" and "Select master pages" are checked. Open the PicViewer.aspx source. You will see an asp:content tag. Inside this tag, place the following code:

Collapse
<table width="760px" cellpadding="1" cellspacing="0">
    <tr>
        <td colspan="5"><asp:PlaceHolder ID="galleryPlaceholder" 
            runat="server"></asp:PlaceHolder>
        </td>
    </tr>
    <tr>
        <td bgcolor="#494949" width="700px">
            <asp:Label ID="lblGalleryName" runat="server" 
                CssClass="SubHeadingWhite">&#9660; How to use</asp:Label>
        </td>
        <td bgcolor="#494949"></td>
        <td bgcolor="#494949"><asp:Label ID="lblPhotoName" 
            runat="server" CssClass="SubTitleWhite"></asp:Label></td>
    </tr>
    <tr>
        <td align="center" colspan="5"><asp:Image ID="galleryImage" 
            runat="server" BorderStyle="Solid" 
            BorderWidth="5px" BorderColor="Black" />
        </td>
    </tr>
</table>

The above code places a placeholder called galleryPlaceholder, to which we will add the gallery and photo navigation bars later. Apart from that, you can also see the label, which will show the title of the picture if any, or else shows the number of the picture.

When the PicViewer page is loaded, we load the navigation of the galleries. If this is the first time (no gallery is being displayed), we show the Howtouse.jpg instruction photo. If this is not the first time, i.e. the user has clicked on a gallery, we show the first picture. If the user has clicked on a picture, we show the picture and the title. Following is the code of the Page_Load subroutine:

Collapse
protected void Page_Load(object sender, EventArgs e)
{
    ContentInfoLoader cil = new ContentInfoLoader();
    string galleriesPath = "";
    if (Session["PicRootPath"] != null && 
        Session["PicRootPath"].ToString() != "")
    {
        galleriesPath = Session["PicRootPath"].ToString();
    }
    else
    {
        galleriesPath = cil.PicRootDefaultPath;
        Session["PicRootPath"] = galleriesPath;
    }
     
    LoadGalleriesNav(galleriesPath,cil);
    if (Request["gallery"] != "" && Request["gallery"] != null)
    {
        lblGalleryName.Text = Request["gallery"];
        Int32 photoCount = 
            LoadPhotosNav(Request["gallery"], galleriesPath, cil);
        string photoName;
        if (Request["photo"] == "" || Request["photo"] == null)
        {
            //If the user has just clicked on

            //the gallery, load the first photo

            photoName = cil.GetPhotoList(Request["gallery"], 
                Server.MapPath(galleriesPath))[0];
            photoName = photoName.Substring(photoName.LastIndexOf("\\"));
        }
        else
        {
            //Otherwise load the photo as in the querystring
            photoName = Request["photo"];
        }
        char[] charSeparators = new char[] { '~', '.' };
        if (photoName.Contains("~"))
        {
            string photoTitle = photoName.Split(charSeparators)[1];
            lblPhotoName.Text = photoTitle.Replace("_", " ");
        }
        else
        {
            lblPhotoName.Text = photoName.Split(charSeparators)[0];
        }
        galleryImage.ImageUrl = galleriesPath + 
            Request["gallery"] + "/pics/" + photoName;
    }
    else
    {
        galleryImage.ImageUrl = galleriesPath + "Howtouse.jpg";
    }
}

The navigation for the gallery and photos are basically unordered lists formatted using CSS. There are some major differences between the gallery list and the photos list, apart from the obvious size, shape and color:

  • Gallery list, when we mouse-over, we see the name of the gallery.
  • Photo list, when we mouse-over, we see the title if the thumbs directory doesn't exist, else we see the thumbnail and the title.

In both navigations, if a particular gallery is selected or a particular gallery and a photo is selected, those items are grayed out and cannot be selected. Apart from this, most of the code is quite simple and self-explanatory. Please let me know if further explanation is required. Following is the code:

Collapse
/// <summary>

/// This method is supposed to load the navigation for the galleries

/// </summary>

public void LoadGalleriesNav(string galleriesPath, ContentInfoLoader cil)
{
    string[] galleryPathList = new string[1];

    // Load the path info for all the galleries

    if (galleriesPath != "")
    {
        galleryPathList = 
            cil.GetGalleryPaths(Server.MapPath(galleriesPath));
    }

    // Generate the unordered list

    HtmlGenericControl blstGalleries = new HtmlGenericControl("ul");
    blstGalleries.Attributes.Add("id", "navlist_a");

    // Generate the navigation for the galleries

    foreach (string galleryPath in galleryPathList)
    {
        string galleryName = 
            galleryPath.Substring(galleryPath.LastIndexOf("\\") + 1);
        HtmlGenericControl galleryListItem = new HtmlGenericControl("li");
        HtmlAnchor galleryAnchor = new HtmlAnchor();
        if (Request["gallery"] != "" && Request["gallery"] != null)
        {
            // If the gallery has not been chosen, generate a link
            if (Request["gallery"].ToUpper() != galleryName.ToUpper())
            {
                galleryAnchor.Attributes.Add("onMouseOver", "ddrivetip('" + 
                    galleryName.ToUpper() + "', " + 
                    galleryName.Length * 7 + ")");
                galleryAnchor.Attributes.Add("onMouseOut", "hideddrivetip()");
                galleryAnchor.HRef = "PicViewer.aspx?gallery=" + galleryName;
                galleryAnchor.InnerHtml = "<em></em>";
            }
            else
            {
                // if a gallery has been chosen
                // already then gray out the selection
                galleryAnchor.Disabled = true;
                galleryAnchor.InnerHtml = "<em style='border-top" + 
                    ":1em solid #696969'></em>";
            }
        }
        else
        {// If the gallery has not been chosen, generate a link
            galleryAnchor.Attributes.Add("onMouseOver", "ddrivetip('" + 
                galleryName.ToUpper() + "', " + 
                galleryName.Length * 7 + ")");
            galleryAnchor.Attributes.Add("onMouseOut", "hideddrivetip()");
            galleryAnchor.HRef = "PicViewer.aspx?gallery=" + galleryName;
            galleryAnchor.InnerHtml = "<em></em>";
        }
        // add the anchor to the list
        galleryListItem.Controls.Add(galleryAnchor);
        blstGalleries.Controls.Add(galleryListItem);
    }
    galleryPlaceholder.Controls.Add(blstGalleries);
}


/// <summary>
/// Load the navigation for the photos
/// </summary>
public Int32 LoadPhotosNav(string galleryName, 
    string galleriesPath, ContentInfoLoader cil)
{
    string[] photoList = new string[1];
    if (galleriesPath!= "")
    {
        photoList = cil.GetPhotoList(galleryName, 
            Server.MapPath(galleriesPath));
    }
    if (photoList != null && photoList.Length != 0)
    {
        HtmlGenericControl blstPhotos = new HtmlGenericControl("ul");
        blstPhotos.Attributes.Add("id", "navlist_b");

        foreach (string iPhotoName in photoList)
        {
            string photoName;
            photoName = 
                iPhotoName.Substring(iPhotoName.LastIndexOf("\\") + 1);
            HtmlGenericControl photoListItem = new HtmlGenericControl("li");
            HtmlAnchor photoAnchor = new HtmlAnchor();
            string originalPhotoName = photoName;
            char[] charSeparators = new char[] { '~','.' };
            string photoTitle = "";
            if (photoName.Contains("~"))
            {
                photoTitle = photoName.Split(charSeparators)[1];
                photoName = photoName.Split(charSeparators)[0] + ".JPG";
            }

            if (Request["photo"] != "" && Request["photo"] != null)
            {
                // if a photo has been selected then we need
                // to show that square as gray otherwise
                // clickable and mouseover effects.
                if (Request["photo"].ToUpper() != photoName.ToUpper())
                {
                    if (Directory.Exists(Server.MapPath(galleriesPath + 
                        galleryName + "/thumbs/")))
                    {
                        photoAnchor.Attributes.Add("onMouseOver", 
                            "ddrivetip('<img src=\\'" + 
                            ResolveUrl(galleriesPath) + galleryName + 
                            "/thumbs/" + photoName + 
                            "\\' /><br>" + 
                            photoTitle.Replace("_", " ") + "', " + 
                            photoTitle.Length + ")");
                    }
                    else
                    {
                        if (photoTitle != "")
                        {
                            photoAnchor.Attributes.Add("onMouseOver", 
                                "ddrivetip('" + photoTitle.Replace("_", 
                                " ") + "', " + photoTitle.Length + ")");
                        }
                        else
                        {
                            photoAnchor.Attributes.Add("onMouseOver", 
                                "ddrivetip('" + photoName + "', " + 
                                photoName.Length + ")");
                        }
                    }

                    photoAnchor.Attributes.Add("onMouseOut", 
                        "hideddrivetip()");
                    photoAnchor.HRef = "PicViewer.aspx?gallery=" + 
                        galleryName + "&photo=" + originalPhotoName;
                    photoAnchor.InnerHtml = "<em></em>";
                }
                else
                {
                    photoAnchor.Disabled = true;
                    photoAnchor.InnerHtml = "<em style='border-top" + 
                        ":0.5em solid #696969'></em>";
                }
            }
            else
            {
                if (Directory.Exists(Server.MapPath(galleriesPath + 
                    galleryName + "/thumbs/")))
                {
                    photoAnchor.Attributes.Add("onMouseOver", 
                        "ddrivetip('<img src=\\'" + 
                        ResolveUrl(galleriesPath) + 
                        galleryName + "/thumbs/" + photoName + 
                        "\\' /><br>" + photoTitle.Replace("_", 
                        " ") + "', " + photoTitle.Length + ")");
                }
                else
                {
                    if (photoTitle != "")
                    {
                        photoAnchor.Attributes.Add("onMouseOver", 
                            "ddrivetip('" + 
                            photoTitle.Replace("_", " ") + "', " + 
                            photoTitle.Length + ")");
                    }
                    else
                    {
                        photoAnchor.Attributes.Add(
                            "onMouseOver", "ddrivetip('" + 
                            photoName + "', " + photoName.Length + ")");
                    }
                }

                photoAnchor.Attributes.Add("onMouseOut", "hideddrivetip()");
                photoAnchor.HRef = "PicViewer.aspx?gallery=" + galleryName + 
                                   "&photo=" + originalPhotoName;
                photoAnchor.InnerHtml = "<em></em>";
            }
            photoListItem.Controls.Add(photoAnchor);
            blstPhotos.Controls.Add(photoListItem);
        }
        galleryPlaceholder.Controls.Add(blstPhotos);
        return photoList.Length;
    }
    else
    {
        return 0;
    }
}
Create New Account
help
visual studio installation problem Actually, my OS is Windows Xp with service pack2.I added service pack3 to install visual studio2010.after that i tryed to installed, but am getting SETUP FAILED due to "Windows XP is not installed. [08 / 10 / 11, 14:26:00] VS70pgui: [2] DepCheck indicates Microsoft Visual F# 2.0 Runtime was not attempted to be installed. [08 / 10 / 11, 14:26:00] VS70pgui: [2] DepCheck indicates Microsoft Visual Studio Macro Tools was not attempted to be installed. [08 / 10 / 11, 14:26:00] VS70pgui not attempted to be installed. [08 / 10 / 11, 14:26:00] VS70pgui: [2] DepCheck indicates .NET Framework 4 Multi-Targeting Pack was not attempted to be installed. [08 / 10 / 11, 14:26:01] VS70pgui: [2] DepCheck indicates Microsoft Visual Studio 2010 Professional - ENU was not attempted to be installed. [08 / 10 / 11, 14:26
Frequently asked Interview Questions in ADO.Net hi friends Any one send frequently asked Important questions in C# .Net, ADO .Net, Asp .Net and Sql Server. . . . . . . . tx in Advance. . . . . . Hi, Find this. . (B)What is an IL? (B)What is a B) What is concept of Boxing and Unboxing ? (B) What is the difference between VB.NET and C#? (I) what is the difference between System exceptions and Application exceptions? (I)What is CODE Access security? (I)What is a satellite assembly? (A) How to prevent my .NET DLL to be decompiled? (I) what is the difference between Convert.toString and .toString () method
choosen the Blog post from here This means the installation should be on a single server as Domain Controller , as MS SQL database server and as MOSS2007 server farm. Only one uses should be used. Thats what I have done, I followed the I am reading the logfiles placed under "c: \ program files \ common files \ microsoft shared \ web server extensions \ 12 \ logs". I don't find any relavant information regarding authentication or what else von der Anmeldung angeforderte 'SharePoint_07_Config'-Datenbank kann nicht geöffnet werden. Fehler bei der Anmeldung.' Source: '.Net SqlClient Data Provider' Number: 4060 State: 1 Class: 11 Procedure: '' LineNumber: 65536 Server: 'd-it5-sptest-dc' 03 / 04 / 2010 13:53:11.35 OWSTIMER.EXE (0x0980) 0x0988 Services Database 880j High SqlError: 'Fehler bei der Anmeldung für den Benutzer 'SPTEST \ spadmin'.' Source: '.Net SqlClient Data Provider' Number: 18456 State: 1 Class: 14 Procedure: '' LineNumber: 65536 Server: 'd-it5
Interview Questions for .NET Framework This article is specially for the users those are in development or want to be a .net developer • To test a Web Service you must create a windows application or web application to consume this service? It is True / False? FALSE How many classes can a single.NET DLL contain? Answer1: As many Answer2: One or more What are good ADO.NET object(s) to replace the ADO Recordset object? The differences includes In ADO, the in memory representation of data is the recordset. In ADO.net, it is the dataset A recordset looks like a single table in ADO In contrast, a dataset is a collection of one or more tables in ADO.net ADO is designed primarily for connected access ADO net the disconnected access to the database is used In ADO you communicate with the database by making calls to an OLE DB provider. In ADO.NET you communicate with the database through a data adapter (an OleDbDataAdapter, SqlDataAdapter, OdbcDataAdapter, or OracleDataAdapter