Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Ajax
Is it possible to preview the excel file content without uploading but after selected
 
using ajax.....
Posted 5-Dec-12 1:35am
Comments
aspnet_regiis -i at 5-Dec-12 9:11am
   
yes

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Yes you can. You can use JSON and Web Service.
 
<input type="file" id="files" name="files[]" multiple />
 

 <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.
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 338
1 _Amy 290
2 Maciej Los 260
3 Manfred R. Bihy 200
4 OriginalGriff 195
0 OriginalGriff 7,445
1 Sergey Alexandrovich Kryukov 6,347
2 Maciej Los 3,799
3 Peter Leow 3,558
4 CHill60 2,702


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 5 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100