当前位置: 首页 > news >正文

net8:简易的文件磁盘管理操作二(包括文件以及文件夹的编辑创建删除移动拷贝重命名等)...

原文发布时间为:2008-08-07 —— 来源于本人的百度文章 [由搬家工具导入]

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.Text;

public partial class Default5 : System.Web.UI.Page
{
   
    private FileStream fs;
    private StreamWriter sw;
    private DirectoryInfo di;
    private FileInfo fi;
    protected void Page_Load(object sender, EventArgs e)
    {
       string fpath = Server.UrlDecode(Request.QueryString["url"]);
       string fname = Server.UrlDecode(Request.QueryString["fname"]);
       string ax = Server.UrlDecode(Request.QueryString["ax"]);
       Session["fpath"] = fpath;
       Session["lastfpath"] = Directory.GetParent(fpath).FullName;
        if (!IsPostBack)
        {         
            switch (ax)
            {
                case "editfile":
                    Panel1.Visible = true;
                    editfile(fpath, fname);
                    break;
                case "editdir":
                    Panel2.Visible = true;
                    editdir(fname);
                    break;
                case "deletedir":
                    Panel3.Visible = true;
                    deletedir(fname);
                    break;
                case "deletefile":
                    Panel4.Visible = true;
                    deletefile(fname);
                    break;              
                case "movefile":
                    Panel5.Visible = true;
                    movefile(fname,fpath);
                    break;
                case "movedir":
                    Panel6.Visible = true;
                    movedir(fname,fpath);
                    break;
                case "copyfile":
                    Panel7.Visible = true;
                    copyfile(fpath);
                    break;
                case "copydir":
                    Panel8.Visible = true;
                    copydir(fpath);
                    break;
            }
        }
    }
    protected void TextBox2_TextChanged(object sender, EventArgs e)
    {

    }

    protected void editfile(string fpath,string fname)
    {
        TextBox1.Text=fname;
        TextBox2.Text = File.ReadAllText(fpath, Encoding.Default);
    }


    protected void Button1_Click(object sender, EventArgs e)
    {

        fs = new FileStream(Session["fpath"].ToString(), FileMode.Create, FileAccess.Write);
        sw = new StreamWriter(fs, Encoding.Default);
        sw.WriteLine(TextBox2.Text);
        sw.Close();
        fs.Close();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default4.aspx?fpath="+Session["lastfpath"].ToString());
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        di = new DirectoryInfo(Session["fpath"].ToString());
        string newpath = Session["lastfpath"].ToString() + "\\" + TextBox3.Text;
        di.MoveTo(newpath);
    }
    protected void editdir(string fname)
    {
        Label1.Text = fname;
    }
    protected void deletedir(string fname)
    {
        Label2.Text = fname;
    }
    protected void deletefile(string fname)
    {
        Label3.Text = fname;
    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        di = new DirectoryInfo(Session["fpath"].ToString());
        di.Delete();
        Response.Write("<script>alert('成功删除')</script>");
        Response.Redirect("Default4.aspx?fpath=" + Session["lastfpath"].ToString());
    }
    protected void Button7_Click(object sender, EventArgs e)
    {
        fi = new FileInfo(Session["fpath"].ToString());
        fi.Delete();
        Response.Write("<script>alert('成功删除')</script>");
        Response.Redirect("Default4.aspx?fpath=" + Session["lastfpath"].ToString());
    }
    protected void movefile(string fname,string fpath)
    {
        Label5.Text = fname;
        Label4.Text = Session["lastfpath"].ToString();
        TextBox4.Text = Session["lastfpath"].ToString();
    }
    protected void movedir(string fname, string fpath)
    {
        Label6.Text = fname;
        Label7.Text = Session["lastfpath"].ToString();
        TextBox5.Text = Session["lastfpath"].ToString();
    }
    protected void Button9_Click(object sender, EventArgs e)
    {
        fi = new FileInfo(Session["fpath"].ToString());
        string newfpath =TextBox4.Text+";
        fi.MoveTo(newfpath);
        Response.Redirect("Default4.aspx?fpath=" +TextBox4.Text);
    }
    protected void Button11_Click(object sender, EventArgs e)
    {
        di = new DirectoryInfo(Session["fpath"].ToString());
        string newfpath =TextBox5.Text+";
        di.MoveTo(newfpath);
        Response.Redirect("Default4.aspx?fpath=" +TextBox5.Text);
    }
    protected void copyfile(string fpath)
    {
        Label8.Text = fpath;
        TextBox6.Text = fpath;
    }

    protected void Button13_Click(object sender, EventArgs e)
    {
        fi = new FileInfo(Label8.Text);
        fi.CopyTo(TextBox6.Text);
        Response.Redirect("Default4.aspx?fpath=" + TextBox6.Text.Substring(0,TextBox6.Text.LastIndexOf("));
    }

    protected void copydir(string fpath)
    {
        Label9.Text = fpath;
        TextBox7.Text = fpath;
    }

    protected void Button15_Click(object sender, EventArgs e)
    {
         dirCopy(Label9.Text,TextBox7.Text);     
         Response.Redirect("Default4.aspx?fpath="+TextBox7.Text.Substring(0,TextBox7.Text.LastIndexOf("));
    }
    protected void dirCopy(string oldpath,string newpath)
    {
         di = new DirectoryInfo(oldpath);
        foreach(FileSystemInfo fsi in di.GetFileSystemInfos())
        {
            if(fsi is FileInfo)
            {
                fi = (FileInfo)fsi;
                if(!Directory.Exists(newpath))
                {
                   DirectoryInfo newDir= Directory.CreateDirectory(newpath);
                   fi.CopyTo(newDir.FullName+");
                }            
                else
               {
                   fi.CopyTo(newpath+");
               }
            }
            else
            {
                DirectoryInfo child_di=(DirectoryInfo)fsi;
                string olddir=child_di.FullName;
                string dirname=child_di.FullName.Substring(child_di.FullName.LastIndexOf(");
                string newchildpath=Path.Combine(newpath,dirname);
                if(!Directory.Exists(olddir))
                    Directory.CreateDirectory(olddir);
                dirCopy(olddir,newchildpath);
            }

       }
    }
}

转载于:https://www.cnblogs.com/handboy/p/7143809.html

相关文章:

  • HashMap HashTable和ConcurrentHashMap的区别
  • 响应式移动端去除css的hover和jq的hover还有input在苹果下的默认样式
  • Codeforces Beta Round #96 (Div. 1) C. Logo Turtle —— DP
  • 【RQNOJ】460 诺诺的队列
  • JS的join方法
  • java selenium (十四) 处理Iframe 中的元素
  • 日志架构
  • 各种定位方式
  • JAVA个人小程序GUI篇-收银(标签、按钮、复选框、下拉标、文本域、表格······)...
  • [bzoj2957]楼房重建
  • 杨辉三角的几种方法
  • 标题四
  • 3种上传图片并实现预览的方法
  • 暑假小集训
  • [无线路由] “免费”斐讯K2路由器刷OpenWRT(实战MWAN多宽带网速叠加)
  • [Vue CLI 3] 配置解析之 css.extract
  • Android开发 - 掌握ConstraintLayout(四)创建基本约束
  • Angular数据绑定机制
  • CentOS 7 修改主机名
  • Docker容器管理
  • ES6简单总结(搭配简单的讲解和小案例)
  • Object.assign方法不能实现深复制
  • PHP变量
  • React Native移动开发实战-3-实现页面间的数据传递
  • spring boot下thymeleaf全局静态变量配置
  • SQLServer之创建显式事务
  • TiDB 源码阅读系列文章(十)Chunk 和执行框架简介
  • 安装python包到指定虚拟环境
  • 纯 javascript 半自动式下滑一定高度,导航栏固定
  • 干货 | 以太坊Mist负责人教你建立无服务器应用
  • 关于List、List?、ListObject的区别
  • 记录一下第一次使用npm
  • 浏览器缓存机制分析
  • 面试遇到的一些题
  • 嵌入式文件系统
  • 如何优雅的使用vue+Dcloud(Hbuild)开发混合app
  • 什么是Javascript函数节流?
  • 实战|智能家居行业移动应用性能分析
  • AI算硅基生命吗,为什么?
  • #图像处理
  • $ git push -u origin master 推送到远程库出错
  • ()、[]、{}、(())、[[]]等各种括号的使用
  • (附源码)springboot 智能停车场系统 毕业设计065415
  • (附源码)ssm捐赠救助系统 毕业设计 060945
  • (淘宝无限适配)手机端rem布局详解(转载非原创)
  • (一)Linux+Windows下安装ffmpeg
  • (转)一些感悟
  • (转载)PyTorch代码规范最佳实践和样式指南
  • ***测试-HTTP方法
  • .[hudsonL@cock.li].mkp勒索病毒数据怎么处理|数据解密恢复
  • .net core 客户端缓存、服务器端响应缓存、服务器内存缓存
  • .NET 应用启用与禁用自动生成绑定重定向 (bindingRedirect),解决不同版本 dll 的依赖问题
  • .NET 指南:抽象化实现的基类
  • .NET文档生成工具ADB使用图文教程
  • /3GB和/USERVA开关