首页 > Web开发 > 详细

dotnet文件操作

时间:2016-05-11 21:39:34      阅读:148      评论:0      收藏:0      [点我收藏+]
 /// <summary>
        /// 创建文件夹
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
        }
        /// <summary>
        /// 删除文件夹
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button2_Click(object sender, EventArgs e)
        {
            if (Directory.Exists(path))
            {
                Directory.Delete(path);
            }
        }
        /// <summary>
        /// 移动文件夹
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button3_Click(object sender, EventArgs e)
        {
            Directory.Move(path, newpath);
        }
        /// <summary>
        /// 创建文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button4_Click(object sender, EventArgs e)
        {
            if (!File.Exists(newpath + @"\myfile.txt"))
            {
                File.CreateText(newpath + @"\myfile.txt");
            }
            Response.Write(String.Format("The number of files in {0} is {1}", newpath, Directory.GetFiles(newpath).Length));
        }
        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button5_Click(object sender, EventArgs e)
        {
            if (File.Exists(newpath + @"\myfile.txt"))
            {
                File.Delete(newpath + @"\myfile.txt");
            }
        }
        /// <summary>
        /// 移动文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button6_Click(object sender, EventArgs e)
        {
            File.Move(newpath + @"\myfile.txt", path + @"\file.txt");
        }

 

dotnet文件操作

原文:http://www.cnblogs.com/EasonJim/p/5483315.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!