我正在帮助创建一个允许以下内容的字节数组:
我已经有以下代码将文件放入字节数组中,但这是在最后一部分。
byte[] filebytes;
st.birth_certificate = detail[4];
downloadfile.HTML = detail[4];
downloadfile.fileName = downloadfile.GetFileNameFromUrl(st.birth_certificate);
downloadfile.toLocation = @"c:\temp\" + downloadfile.fileName;
if (downloadfile.DownloadFile())
{
filebytes= File.ReadAllBytes(downloadfile.toLocation);
st.birth_certificate_file = filebytes;
}
非常感谢任何帮助。
答案 0 :(得分:0)
更好地使用BinaryReader。我不确定数字是十六进制值还是ascii数字(或Big / Little Endian)所以我做了一点猜测。代码可能需要一些小的调整:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string URL = "enter you url here";
FileStream sReader = File.OpenRead(URL);
BinaryReader reader = new BinaryReader(sReader);
int filenameLength = reader.ReadInt16();
string filename = Encoding.UTF8.GetString(reader.ReadBytes(filenameLength));
int year = int.Parse(Encoding.UTF8.GetString(reader.ReadBytes(4)));
int month = int.Parse(Encoding.UTF8.GetString(reader.ReadBytes(2)));
int day = int.Parse(Encoding.UTF8.GetString(reader.ReadBytes(2)));
DateTime date = new DateTime(year, month, day);
short number1 = reader.ReadInt16();
int number2 = reader.ReadInt32();
byte[] data = reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position + 1));
}
}
}