Angular save file as csv result in Failed- network error Only on Chrome

Question!

I'm using the following code to save file as csv.

$scope.saveCSVFile = function (result)
{
    var a         = document.createElement('a');
    a.href = 'data:application/csv;charset=utf-8,' + encodeURIComponent(result.data);
    a.target      = '_blank';
    a.download    =  $scope.getFileNameFromHttpResponse(result);
    document.body.appendChild(a);
    a.click();
    $scope.isReportInProgress = false;
};

The file is working on most of the cases but for some reason when the file is larger than 10MB i get "Failed - Network Error".

It happens only on chrome.

I tried to search the web for this issue and couldn't find anything relevant.

Can you think of an idea why does it happens? or maybe use a different save file method that will work on chrome/firefox/IE instead of my function?



Answers

I was finally used this one, hope it can help the next one encounter this issue:

 var blob = new Blob([result.data], {type: 'text/csv'});
            var filename =  $scope.getFileNameFromHttpResponse(result);
            if(window.navigator.msSaveOrOpenBlob) {
                window.navigator.msSaveBlob(blob, filename);
            }
            else{
                var elem = window.document.createElement('a');
                elem.href = window.URL.createObjectURL(blob);
                elem.download = filename;
                document.body.appendChild(elem);
                elem.click();
                document.body.removeChild(elem);
            }


Easiest way is to create validation in separate column.

enter image description here

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <style type="text/css">
        .required {
            color: #e31937;
            font-family: Verdana;
            margin: 0 5px;
        }

        .field-validation-error {
            color: #e31937;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <br />
        <div class="container form-horizontal">
            <div class="form-group">
                <asp:Label runat="server"
                    AssociatedControlID="txtBox"
                    CssClass="col-xs-12 col-sm-4 control-label">
                    Address 
                    <span class="required">*</span>
                </asp:Label>
                <div class="col-xs-12 col-sm-4 ">
                    <asp:TextBox ID="txtBox" runat="server"
                        CssClass="form-control" />
                </div>
                <div class="col-xs-12 col-sm-4 form-control-static">
                    <asp:RequiredFieldValidator ID="rfvLine1"
                        ControlToValidate="txtBox" runat="server"
                        Display="Dynamic"
                        CssClass="field-validation-error"
                        Text="Line 1 is required." />
                </div>
            </div>
            <div class="form-group">
                <div class="col-xs-12 col-sm-offset-4 col-sm-4 ">
                    <asp:Button runat="server" ID="SubmitButton"
                        Text="Submit" CssClass="btn btn-primary" />
                </div>
            </div>
        </div>
    </form>
</body>
</html>
By : Win


This video can help you solving your question :)
By: admin