简体   繁体   中英

Retriving the Binary Data and load in a related File Viewer

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....

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();

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.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM