Reputation: 53
I uploaded the File using RadUpload Control and store the data in Binary Format Now I got the Binary Data and I need to load the Retrived Binary Data in Respective File Viewer...If (Docx in Word Pdf In Adobe....if Text in text viewer)
Here is the code That I got Binary Data
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");
I got the Data in Byte Array now I need to store the data in Docx or Pdf or....
Upvotes: 1
Views: 226
Reputation: 53
Tried like this....(but still didnt get the result)
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();
Upvotes: 0
Reputation: 154
you can use something like File.WriteAllBytes() to correctly write a byte array to file.
simply do
File.WriteAllBytes("D:\\filename.docx", Data);
and that should do it.
Upvotes: 0
Reputation: 53
I tried Something Like this but created Docx file with out the data that I uploaded.......
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();
Upvotes: 1