0

Here is the code I tried to store the data in binary format for the uploaded file...................

protected void Button1_Click(object sender, EventArgs e)
{
int PartyRowId = 0;
foreach (UploadedFile file in AsyncUpload1.UploadedFiles)

{
    byte[] bytes = new byte[file.ContentLength];
    file.InputStream.Read(bytes, 0, Convert.ToInt32(file.ContentLength));
    string json3 = "{'value1':" + value+ ",'value2':" + value+ ",'value3':" + value+ ",'PartyDoc':" + bytes + "}";

}
}


i got the Json as

 {'value1':0,'value2':0,'value3':0,'PartyDoc':System.Byte[]}


not able to retrieve the binary data Please help me......

leppie
  • 115,091
  • 17
  • 196
  • 297
Gopal Reddy
  • 53
  • 1
  • 12

2 Answers2

0

You should use Convert.ToBase64String();

string json3 = "{'value1':" + value+ ",'value2':" + value+ ",'value3':" + value+ ",'PartyDoc':" + Convert.ToBase64String(bytes) + "}";

Then on the other side you can useConvert.FromBase64String();

prospector
  • 3,389
  • 1
  • 23
  • 40
  • Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query. – Gopal Reddy Jan 10 '15 at 09:46
0

done with the conversion as below...

CONVERT(varbinary(100), CONVERT(varchar(max),@variable))

Gopal Reddy
  • 53
  • 1
  • 12
  • sql server.it is inserting when I am done at Executing stored procedure...but when I am trying to insert from Application Scenario.... – Gopal Reddy Jan 12 '15 at 04:30