将pdf文件的内容(byte [])转换为c#中的fileinfo [] [英] convert content(byte[]) of pdf files to fileinfo[] in c#
本文介绍了将pdf文件的内容(byte [])转换为c#中的fileinfo []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开发了winform应用程序,用于读取文件名,文件路径,扩展名,文件大小,内容
of pdf file.all这些属性运行良好,除了内容pdf file.content of
pdf文件格式为bytearray。我想将bytearray转换为fileinfo数组。
我的代码:
i have develop winform app for reading filename,path of file,extension,filesize,content
of pdf file.all these properties are working well except content of pdf file.content of
pdf file format is bytearray. i want convert bytearray to fileinfo array.
my code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using System.Windows.Forms;
using pdf_app.Lib;
namespace pdf_app
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ArrayList files = new ArrayList();
string path = @"D:\Data Sets\Enron";
DirectoryInfo d = new DirectoryInfo(path);
FileInfo[] pdffilenames = d.GetFiles("*.pdf");
foreach(FileInfo pdffilename in pdffilenames)
{
fileatt f = new fileatt();
f.fFullName = pdffilename.FullName;
f.fName = pdffilename.Name;
f.FileSize = pdffilename.Length;
f.fExtension = pdffilename.Extension;
byte[] bytes = File.ReadAllBytes(pdffilename.FullName);
}
MessageBox.Show("successfully");
}
}
}
Fileatt.cs
Fileatt.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace pdf_app.Lib
{
class fileatt
{
public long FileSize { get; set; }
public string fName { get; set; }
public string fFullName { get; set; }
public string fExtension { get; set; }
public string fContent { get; set; }
}
}
请帮帮我。
please help me.
推荐答案
好的,所以那么为什么你的foreach循环创建一个fileatt对象,设置它的属性然后扔掉它?你没有对你刚创建的那个对象做任何事情。
另外,你的fileatt.fContent属性被输入为一个字符串,你得到的是byte [] ReadAllBytes不会转换为任何含义。您必须将该字符串更改为byte []才能使其有意义。
OK, so why then is your foreach loop creating a fileatt object, setting its properties and then throwing it away? You're not doing anything with that object you just created.
Also, your fileatt.fContent property is typed as a string, which the byte[] you get when you ReadAllBytes will not convert to with any meaning. You have to change that string to byte[] in order for it to make any sense.
这篇关于将pdf文件的内容(byte [])转换为c#中的fileinfo []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文