delete.aspx.cs

来自「这个源代码是我在没有参考任何现成的代码的情况下一个字母一个字母敲进去的.目前实现」· CS 代码 · 共 84 行

CS
84
字号
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 FTP
{
	public class delete : System.Web.UI.Page
	{
		private void Page_Load(object sender, System.EventArgs e)
		{
			// page requires a querystring like: Type=File&Name=someName OR Type=Folder&Name=someName
			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("default.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("default.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 Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?