• 大小: 37.48 KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-10-01
  • 语言: C#
  • 标签: c#  读取  txt  cs  

资源简介

c#读取txt文件,cs文件,html文件,实现用户自定义目录,本程序是vs2008版,2005版需要升级

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace 读取txt文件
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public string filename;
        private void Form1_Load(object sender EventArgs e)
        {
            
        }

        private void listBox1_Click(object sender EventArgs e)
        {
            if (listBox1.SelectedItems.Count == 0)
            {
                MessageBox.Show(“您没有选择任何文件“);
            }
            else
            {
                ultraTextEditor1.Text = ““;
                string timelog = ““;
                timelog = listBox1.SelectedItem.ToString();
                string x = filename + “\\“ + timelog;
                StreamReader sr = new StreamReader(x);
                do
                {
                    string strLine = ““;
                    strLine = sr.ReadLine();//  读取一行字符并返回
                    ultraTextEditor1.Text += strLine + “\r\n“;
                } while (!sr.EndOfStream);
                sr.Close();
            }
        }

        private void button1_Click(object sender EventArgs e)
        {
            FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                ultraTextEditor2.Text=folderBrowserDialog1.SelectedPath;
            }
            filename = ultraTextEditor2.Text;
            if (!File.Exists(filename))
            {
                Directory.CreateDirectory(filename);
            }
            string path = filename;
            System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(path);
            //dir.GetFiles(“*.cs“)或dir.GetFiles(“*.html“) 也支持读取cs文件和html文件
            foreach (System.IO.FileInfo file in dir.GetFiles(“*.txt“))
            {
                string message = file.Name;
                listBox1.Items.Add(message);
            }
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      20480  2009-06-16 09:45  读取txt文件\读取txt文件\bin\Debug\读取txt文件.exe

     文件      26112  2009-06-16 09:45  读取txt文件\读取txt文件\bin\Debug\读取txt文件.pdb

     文件       5632  2005-11-11 22:25  读取txt文件\读取txt文件\bin\Debug\读取txt文件.vshost.exe

     文件       2249  2009-06-16 09:45  读取txt文件\读取txt文件\Form1.cs

     文件       4659  2009-06-16 09:43  读取txt文件\读取txt文件\Form1.Designer.cs

     文件       6023  2009-06-16 09:43  读取txt文件\读取txt文件\Form1.resx

     文件      18401  2009-06-16 08:58  读取txt文件\读取txt文件\obj\Debug\ResolveAssemblyReference.cache

     文件        842  2009-06-16 09:43  读取txt文件\读取txt文件\obj\Debug\读取txt文件.csproj.GenerateResource.Cache

     文件      20480  2009-06-16 09:45  读取txt文件\读取txt文件\obj\Debug\读取txt文件.exe

     文件        485  2009-06-16 09:43  读取txt文件\读取txt文件\obj\Debug\读取txt文件.exe.licenses

     文件        180  2009-06-16 09:43  读取txt文件\读取txt文件\obj\Debug\读取txt文件.Form1.resources

     文件      26112  2009-06-16 09:45  读取txt文件\读取txt文件\obj\Debug\读取txt文件.pdb

     文件        180  2009-06-16 08:49  读取txt文件\读取txt文件\obj\Debug\读取txt文件.Properties.Resources.resources

     文件        364  2009-06-16 09:46  读取txt文件\读取txt文件\obj\读取txt文件.csproj.FileList.txt

     文件        474  2009-06-16 08:40  读取txt文件\读取txt文件\Program.cs

     文件       1188  2009-06-16 08:40  读取txt文件\读取txt文件\Properties\AssemblyInfo.cs

     文件        164  2009-06-16 09:43  读取txt文件\读取txt文件\Properties\licenses.licx

     文件       2884  2009-06-16 08:40  读取txt文件\读取txt文件\Properties\Resources.Designer.cs

     文件       5612  2009-06-16 08:40  读取txt文件\读取txt文件\Properties\Resources.resx

     文件       1098  2009-06-16 08:40  读取txt文件\读取txt文件\Properties\Settings.Designer.cs

     文件        249  2009-06-16 08:40  读取txt文件\读取txt文件\Properties\Settings.settings

     文件       3789  2009-06-16 08:58  读取txt文件\读取txt文件\读取txt文件.csproj

     文件        934  2009-06-16 08:40  读取txt文件\读取txt文件.sln

    ..A..H.      8192  2009-06-16 08:40  读取txt文件\读取txt文件.suo

     目录          0  2009-06-16 08:40  读取txt文件\读取txt文件\obj\Debug\TempPE

     目录          0  2009-06-16 08:49  读取txt文件\读取txt文件\bin\Debug

     目录          0  2009-06-16 09:45  读取txt文件\读取txt文件\obj\Debug

     目录          0  2009-06-16 08:40  读取txt文件\读取txt文件\bin

     目录          0  2009-06-16 08:49  读取txt文件\读取txt文件\obj

     目录          0  2009-06-16 09:43  读取txt文件\读取txt文件\Properties

............此处省略5个文件信息

评论

共有 条评论