Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I have created ActiveX Control that will convert file into bytes array.
I am consuming that activeX in my web application using javascript.In IE8 I am able to get byte array for the file but above IE8 it's giving undefined while returning.

I am posting my javascript code below

C#
function CallFunction() {

            var obj = document.Adstringo;
            var filepath = document.getElementById("Fileupload1").value;            
            obj.Source = filepath;        
            var res = obj.GetFileBytes();  // Call ActiveX Function   
}


In res variable I am getting undefined in IE version greater than 8. In IE8 it is working properly.

What I have tried:

I have tried changing the data types for the function in activeX.

C#
public object GetFileBytes()
        {
            FileStream fs = new FileStream(Source, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);
            Byte[] bytes = br.ReadBytes((Int32)fs.Length);
            br.Close();
            fs.Close();

            return bytes;
        }

I have changed from object to byte[]
Posted
Updated 31-Aug-16 3:49am
v2

1 solution

ActiveX controls will only work in Internet Explorer on Windows, and only if the user allows your site to download the control, and to script ActiveX controls not marked as "safe for scripting".

(Your control is NOT marked as "safe for scripting", is it? Because it's not - it allows a website to read the content of any file on the user's computer, and that is most definitely not "safe".)

Unless you're creating an internal "intranet" site, where you control all of the computers which will access your site, you should avoid using ActiveX controls at all costs.

There is a native file API[^] which works in most browsers[^], including IE10 and above.
JavaScript
function CallFunction() {
    var file = document.getElementById("Fileupload1").files[0];
    
    var reader = new FileReader();
    
    reader.onload = function(e){
        var fileBytes = e.target.result;
        // TODO: Do something with the data
    };
    
    reader.readAsArrayBuffer(file);
}

NB: As of 12th January 2016, only the most current version of Internet Explorer available for a supported operating system receives technical support and security updates. IE8 is no longer supported on the desktop. IE9 is only supported on Vista and Windows Server 2008 / 2008 R2.
Lifecycle support policy FAQ - Internet Explorer[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900