Click here to Skip to main content
15,896,259 members
Articles / Web Development / ASP.NET

Image Map / Hot Spot _ Point Plotting

Rate me:
Please Sign up or sign in to vote.
1.86/5 (3 votes)
11 Jan 20073 min read 27.2K   365   12  
A tool for collecting hot spot coordinates.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

//for txt file manipulation
using System.IO;

public partial class _PointManager : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath("PointLists"));

            ImageList.DataSource = dirInfo.GetFiles("*.*");
            ImageList.DataBind();
        }
    }

    public void ImageList_ItemDataBound(Object sender , DataGridItemEventArgs e)
    {
        //First, make sure we're NOT dealing with a Header or Footer row
        if(e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
        {
            //Now, reference the Button control that the Delete ButtonColumn has been rendered to
            Button deleteButton = (Button)e.Item.Cells[0].Controls[0];

            //We can now add the onclick event handler
            deleteButton.Attributes.Add("onclick", "javascript:return " + 
                       "confirm('Are you sure you want to delete the file " + 
                       DataBinder.Eval(e.Item.DataItem, "Name") + "?')");
        }
    }

    public void ImageList_DeleteFile(Object sender , DataGridCommandEventArgs e )
    {
        //First, get the filename to delete
        String fileName = ImageList.DataKeys[e.Item.ItemIndex].ToString();
        
        //retrive active point list
        String FNAME = Server.MapPath("ListActive.txt");
        StreamReader sr = File.OpenText(FNAME);
        String ActiveList = Server.MapPath(sr.ReadToEnd());
        sr.Close();

        if (fileName == ActiveList)
        {
            activeListMessage.Text = ": YOU CAN'T DELETE ACTIVE LIST :";
        }
        else
        {
            File.Delete(fileName);
            DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath("PointLists"));
            ImageList.DataSource = dirInfo.GetFiles("*.*");
            ImageList.DataBind();
        }
    }

    protected void Page_PreRender()
    {
        String upFolder = Server.MapPath("PointLists/");
        DirectoryInfo dir = new DirectoryInfo(upFolder);
        ImageList2.DataSource = dir.GetFiles("*.*");
        ImageList2.DataBind();
    }
    protected void MakePointListActive_Click(object sender, EventArgs e)
    {
        String PATH = "~//PointLists//" + ImageList2.SelectedValue;

        String FILENAME = Server.MapPath("ListActive.txt");

        StreamWriter sr = File.CreateText(FILENAME);
        sr.Write(PATH);
        sr.Close();
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions