1

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

Gopal Reddy
  • 53
  • 1
  • 12

3 Answers3

1

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();
Gopal Reddy
  • 53
  • 1
  • 12
0

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.

user2835725
  • 154
  • 6
  • can you confirm that Data has information inside of it? besides data being blank the only thing i can think to cause an issue would be insufficient write privilege. – user2835725 Jan 13 '15 at 07:58
0

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();
Gopal Reddy
  • 53
  • 1
  • 12