检索二进制数据并在相关的文件查看器中加载
本文关键字:文件 加载 数据 二进制 检索 | 更新日期: 2023-09-27 18:37:22
我使用 RadUpload 控件上传了文件并以二进制格式存储数据现在我得到了二进制数据,我需要在相应的文件查看器中加载检索的二进制数据......如果(Docx in Word pdf in adobe....如果文本查看器中的文本)
这是我得到二进制数据的代码
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 中,或者......
我尝试了这样的东西,但创建了 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();
你可以
使用类似File.WriteAllBytes()的东西来正确地将字节数组写入文件。
只需做
File.WriteAllBytes("D:''filename.docx", Data);
这应该可以做到。
像这样尝试过....(但仍然没有得到结果)
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();