1

我使用 RadUpload Control 上传了文件并以二进制格式存储数据现在我得到了二进制数据,我需要在相应的文件查看器中加载检索到的二进制数据......如果(Adobe 中的 Word Pdf 中的 Docx ......如果文本在文本查看器中)

这是我得到二进制数据的代码

string json = class.HttpGet("http://localhost/Service/User.svc/ServiceName");
        json = Regex.Unescape(json);
        dt = (DataTable)JsonConvert.DeserializeObject(json.Trim(new Char[] { ' ', '"', '.' }), typeof(DataTable));
        string data=dt.Rows[0]["Document"].ToString();
        byte[] Data = Convert.FromBase64String("data");

我得到字节数组中的数据现在我需要将数据存储在 Docx 或 Pdf 或....

4

3 回答 3

1

我尝试了类似这样的东西,但是在没有上传数据的情况下创建了 Docx 文件......

byte[] Data = Convert.FromBase64String(dt.Rows[0]["Document"].ToString());

        FileStream fs = new FileStream(@"D:\filename.docx", FileMode.Create);
        fs.Write(Data, 0, Data.Length);
        fs.Close();
于 2015-01-13T07:42:41.387 回答
0

您可以使用File.WriteAllBytes() 之类的方法将字节数组正确写入文件。

简单地做

File.WriteAllBytes("D:\\filename.docx", Data);

那应该这样做。

于 2015-01-13T07:54:07.893 回答
0

像这样尝试......(但仍然没有得到结果)

 Response.Buffer = true;

 Response.Charset = "";

 Response.Cache.SetCacheability(HttpCacheability.NoCache);

 Response.ContentType = dt.Rows[0]["RowId"].ToString();

 Response.AddHeader("content-disposition", "attachment;filename="

 + dt.Rows[0]["FileName"].ToString());

  Response.BinaryWrite(Data);

   Response.Flush();

   Response.End();
于 2015-01-13T07:58:04.050 回答