using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;

namespace baoge.Admin
{
	/// <summary>
	/// delete 的摘要说明。
	/// </summary>
	public class delete : System.Web.UI.Page
	{
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(Request.QueryString["Type"] != null && Request.QueryString["Name"] != null)
			{
				// check for the File querystring parameter
				if(Request.QueryString["Type"].ToString() == "File")
				{
					FileInfo file = new FileInfo(Server.MapPath(Server.UrlDecode(Request.QueryString["Name"].ToString())));
					try
					{
						file.Delete();
						// could give user a response, but possibly unnecessary. uncomment next line if required
						// Response.Write("<script>alert('File deleted successfully'); document.location=\"default.aspx\";</script>");			
						Response.Redirect("webfile.aspx");
					}
					catch(Exception ex)
					{
						FTP.ReportError("Could not delete file", ex.ToString(), "If the file has just been created / edited / saved, wait a few seconds for Windows to release the file lock and try again.");
					}	

				}
				else if(Request.QueryString["Type"].ToString() == "Folder")
				{
					try
					{
						DirectoryInfo dir = new DirectoryInfo(Server.MapPath(Server.UrlDecode(Request.QueryString["Name"].ToString())));
						dir.Delete();							
						// could give user a response, but possible unnecessary. uncomment next line if required
						// Response.Write("<script>alert('Folder deleted successfully'); document.location=\"default.aspx\";</script>");			
						Response.Redirect("webfile.aspx");
					}
					catch(IOException IOEx)
					{
						FTP.ReportError("Directory is not empty", IOEx.ToString(), "Remove all sub-files and sub-folders");
					}
					catch(Exception ex)
					{
						FTP.ReportError("Could not delete folder", ex.ToString(), "Check that the folder exists");
					}
				}
				else
					FTP.ReportError("No valid type passed in querystring to page, must be 'Folder' or 'File'. ", "<none>", "You should only arrive at this page from having clicked delete for a file / folder.");
			}
			else
				FTP.ReportError("No 'type' or 'name' paramater passed in querystring to page", "<none>", "You should only arrive at this page from having clicked delete for a file / folder.");
		}
	

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}
