首页 新闻 会员 周边

C# 如何二进制流写入到文档

0
[已解决问题] 解决于 2013-10-16 09:27

我写的方法 GetPrintFile(Filetype,string path,dictionary<string string> para)是用来传回指定格式(比如pdf格式)byte[][] 类型的流文件。

 

但方法 stream.Write(byte[] array,int,int) 第一个参数只接受 byte[] 的一维字节数组。
如何把 byte[][]转换成 byte[],或者是否有另一个方式来实现byte[][]写入到pdf中??
 1   if (dr == DialogResult.OK)
 2             {
 3                 string fileName = saveReportDialog.FileName;
 4 
 5                 Byte[][] results;
 6                 try
 7                 {
 8                     results = rp.GetPrintFile(His.ReportPrinter.FileType.PDF, @"/ReportDeom/spgdemo2鞋面預補", para);
 9                     using (FileStream stream = File.OpenWrite(fileName))
10                     {
11                         //stream.Write(byte[] array,int,int);
12                         stream.Write(results, 0, results.Length);
13                     }
14                 }
15 
16                 catch (Exception exception)
17                 {
18                     HandleException(exception);
19                 }
20             }
< >
分享
最佳答案
0

1、为什么要返回 byte[][] 类型?

2、请学习下交错数组(byte[][])和一维数组(byte[])的使用方式和相互的转换。

http://msdn.microsoft.com/zh-cn/library/vstudio/9b9dty7d.aspx

奖励园豆:5
Launcher | 高人七级 |园豆:45045 | 2013-10-16 09:15

1、为什么要返回 byte[][] 类型?

答:引用的别人写的类库

2、请学习下交错数组(byte[][])和一维数组(byte[])的使用方式和相互的转换。

答:这个就不研究了,

 

现有解决方法:

方案一:二维数组 逐行写入。

 1                 Byte[][] results;
 2                 try
 3                 {
 4                     results = rp.GetPrintFile(His.ReportPrinter.FileType.PDF, @"/ReportDeom/spgdemo2鞋面預補", para);
 5                     using (FileStream stream = File.OpenWrite(fileName))
 6                     {
 7                         //stream.Write(results, 0, results.Length);
 8 
 9                         for (int i = 0; i < results.Length;i++ )
10                         {
11                             stream.Write(results[i], 0, results[i].Length);
12                         }
13 
14                     }
15                 }

方案二:filestream 改用 StreamWriter,reusuls.tostring() 再 StreamWriter(String)

Cornelius | 园豆:80 (初学一级) | 2013-10-16 09:26
其他回答(1)
0
dudu | 园豆:31003 (高人七级) | 2013-10-16 09:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册