c#实现对MP4等文件属性信息的读取以及对txt文件内容的读取

来源:互联网 发布:淘宝上架时间查询 编辑:程序博客网 时间:2024/05/21 09:56

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using Shell32;

namespace ReadText
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            ReadTextFile(@"C:\test\医院名称.MP4");
        }

        //将路径传进去
        private void ReadTextFile(string filePath)
        {
            //需要引用Shell32.dll文件
            ShellClass sc = new ShellClass();
            Folder dir = sc.NameSpace(Path.GetDirectoryName(filePath));
            FolderItem item = dir.ParseName(Path.GetFileName(filePath));
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 50; i++)
            {
                sb.Append(i.ToString());
                sb.Append(":");
                sb.Append(dir.GetDetailsOf(item, i));
                sb.Append("\r\n");

            }

            string c = sb.ToString();
            textBox1.Text = c; //在TextBox上显示

            //读取文件txt内容
           // string[] lines = File.ReadAllLines(filePath);
            //foreach (var line in lines)
            //{
            //    textBox1.AppendText(line + Environment.NewLine);
            //}
        }
    }
}


0 0