⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 delete.aspx.cs

📁 这个源代码是我在没有参考任何现成的代码的情况下一个字母一个字母敲进去的.目前实现了创建文件,读写文件的操作,暂时不支持子目录、长文件名、文件删除、重命名等操作。
💻 CS
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -