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;
using System.IO;
using System.Net.Mail;
using System.Text;
public partial class WebBrowser : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ArrayList viewFile = (ArrayList)Session["viewFile"];
if (!IsPostBack)
{
string path = Request.MapPath("Images");
if (Directory.Exists(path))
{
DirectoryInfo di = new DirectoryInfo(path);
FileInfo[] rgFiles = di.GetFiles("*.jpg");
foreach (FileInfo fi in rgFiles)
{
viewFile.Add(fi.Name);
}
ViewState.Add("SelectedOne", 0);
}
else
{
Directory.CreateDirectory(path);
}
}
Session["viewFile"] = viewFile;
}
public void Display()
{
// displays the first image in the array list
ArrayList viewFile = (ArrayList)Session["viewFile"];
int index = Convert.ToInt32(ViewState["SelectedOne"]);
this.boxPic.ImageUrl = "Images/" + viewFile[index];
this.Download.NavigateUrl = "Images/" + viewFile[index];
}
protected void btnNext_Click(object sender, EventArgs e)
{
ArrayList viewFile = (ArrayList)Session["viewFile"];
int index = Convert.ToInt32(ViewState["SelectedOne"]);
// int index = int.Parse(ViewState["SelectedOne"]);
if (index+1 > viewFile.Count -1)
{
index = 0;
}
index++;
ViewState["SelectedOne"] = index;
this.Display();
}
protected void btnPrevious_Click(object sender, EventArgs e)
{
ArrayList viewFile = (ArrayList)Session["viewFile"];
int index = Convert.ToInt32(ViewState["SelectedOne"]);
if (index-- <=0)
{
index = viewFile.Count-1;
}
index--;
ViewState["SelectedOne"] = index;
this.Display();
}
protected void btnUpload_Click(object sender, EventArgs e)
{
// Specify the path on the server to
// save the uploaded file to.
String savePath = "Images";
// Before attempting to perform operations
// on the file, verify that the FileUpload
// control contains a file.
if (txtBrowse.HasFile)
{
// Get the name of the file to upload.
String fileName = txtBrowse.FileName;
// Append the name of the file to upload to the path.
savePath += fileName;
// Call the SaveAs method to save the
// uploaded file to the specified path.
// This example does not perform all
// the necessary error checking.
// If a file with the same name
// already exists in the specified path,
// the uploaded file overwrites it.
txtBrowse.SaveAs(savePath);
// Notify the user of the name of the file
// was saved under.
lblBrowse.Text = "Your file was saved as " + fileName;
}
else
{
// Notify the user that a file was not uploaded.
lblBrowse.Text = "You did not specify a file to upload.";
}
}
}