Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possible to preview the excel file content without uploading but after selected

using ajax.....
Posted
Comments
bbirajdar 5-Dec-12 9:11am    
yes

1 solution

Yes you can. You can use JSON and Web Service.

HTML
<input type="file" id="files" name="files[]" multiple />



JavaScript
 <script type="text/javascript">

 document.getElementById('files').addEventListener('change', handleFileSelect, false);
function handleFileSelect(evt) {
                var fileUpload = document.getElementById('files');
                var files = evt.target.files; // FileList object
                // Loop through the FileList and render image files as thumbnails.
                for (var i = 0, f; f = files[i]; i++) {
                    var reader = new FileReader();
                    var base64Data;

                        reader.onload = (function (theFile) {
                            return function (e) {
                                base64Data = e.target.result;
				StoreDocument(base64Data);
                            };
                        })(f);
                        // Read in the image file as a data URL.
                        reader.readAsDataURL(f);
                    }
            }


 function StoreDocument(base64Data) {
                $.ajax({
                    type: "POST",
                    url: "DocumentUpload.asmx/Base64ToFile",
                    data: "{ 'base64': '" + base64Data + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                        base64Data = response.d;
                    },
                    failure: function (msg) {
                        alert(msg);
                    }
                });
            }

</script>


Now Create WebService for DocumentUpload.asmx and Make a method Base64ToFile(string base64)
now you can convert the base64 string to byte or you can save to database.

Thank you.
 
Share this answer
 
v2

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