简体   繁体   中英

Microsoft JScript runtime error: Could not complete the operation due to error c00ce514

I wrote a file download code but i get this error when i start it in my projects. Only this code works perfectly fine. But in complex project this error occurred. Can you help about it ? Here is download code

string fileUrl = @filePath + "\\" + _DownloadableProductFileName;
            string newFileName = _DownloadableProductFileName;
            FileStream fs = new FileStream(fileUrl, FileMode.Open, FileAccess.Read);
            byte[] buffer = new byte[(int)fs.Length];
            fs.Read(buffer, 0, (int)fs.Length);
            fs.Close();
            Response.Clear();
            Response.AddHeader("Content-Length", buffer.Length.ToString());
            Response.AddHeader("Content-Disposition", "attachment; filename=" + newFileName);
            Response.BinaryWrite(buffer);
            Response.End();

And the error code is

Microsoft JScript runtime error: Could not complete the operation due to error c00ce514.

Here error occurs.

get_responseData: function XMLHttpExecutor$get_responseData() {
    /// <value type="String" locid="P:J#Sys.Net.XMLHttpExecutor.responseData">The text of the response.</value>
    if (arguments.length !== 0) throw Error.parameterCount();
    if (!this._responseAvailable) {
        throw Error.invalidOperation(String.format(Sys.Res.cannotCallBeforeResponse, 'get_responseData'));
    }
    if (!this._xmlHttpRequest) {
        throw Error.invalidOperation(String.format(Sys.Res.cannotCallOutsideHandler, 'get_responseData'));
    }

    return this._xmlHttpRequest.responseText; //here throw error
},

Just for the protocol (two years late ;). The error occurs when your download code is placed inside an update panel performing an async postback. You must ensure that the request delivering a binary file always performs a synchronous postback so that the browser is able to interprete the binary result file (and not the XMLHttpExecutor who expected html fragments).

Solution: Place the name of your Button as a PostBackTrigger or register the button with

ScriptManager.GetCurrent(Page).RegisterPostBackControl(yourButton)

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