开发者

pass C# byte array to javascript

开发者 https://www.devze.com 2023-02-14 08:34 出处:网络
i have a situation in which i have a byte array of a image in code behind C# class of a webpage (pop up page)

i have a situation in which i have a byte array of a image in code behind C# class of a webpage (pop up page)

protected void ToFile(byte[] byteImage)

{
            string strByte = byteImage.ToString();
            this.Context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup('" + byteImage + "');</script>");
            this.Context.Response.End();
}

i want to get pass byteImage to the handler function i.e .in javascript / on parent page

function onDialogClose(dialogResult,returnValue) {
        if (dialogResult == SP.UI.DialogResult.OK) {
            //var inputBuffer = new System.Byte(returnValue.length);
            //var byte = new Array();
            //byte = returnValue;

how to get the byte array at returnValue (now it contains System.Byte[]) 开发者_开发问答only

is there any way to access C3 byte[] array from Javascript??

thankx


You could use the base64 encoding to encode the byte array safely:

var result = Convert.ToBase64String(bytes);

Of course, in order to access the original byte values in JavaScript, you’ll have to convert it back on the JavaScript side. There is no built-in function for this in JavaScript, but you can probably grab the decodeBase64 implementation from this website.


You could use this

private string Bytes2String(byte[] bytes){
    return "["+string.Join(",",bytes.Select(b=>b.ToString()))+"]";
}

provided you are using .Net 4.0

0

精彩评论

暂无评论...
验证码 换一张
取 消