Click here to Skip to main content
15,890,391 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi..
i want to save a file on server using ajax in mvc.before that i converting file into Binary but i got error"Microsoft JScript runtime error: Unable to get value of the property '0': object is null or undefined" .this is my code..
JavaScript
var file = document.getElementById('ExcelUploader').files[0];
var file_binary = file.getAsBinary();
$.ajax({
               type: "POST",
               url: $("#HidResolvedUrl").val() + "UploadFile/UpFile",
               data: { val: file_binary

               },
               dataType: "json",
               async: true,
               cache: false,
               success: function(msg) { }
           });
Posted
Updated 13-Jun-12 2:25am
v2

1 solution

HI

u can use Uploadify http://valums.com/ajax-upload/[^]

but for this user must have software.

So better in controller itself you can write coding
C#
HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
if (hpf.ContentLength == 0)
continue;
int length = hpf.ContentLength;
byte[] buffer = new byte[length];
hpf.InputStream.Read(buffer, 0, length);
profile.Photo = buffer;

Entity.tablename.add(profile);
Entity.SaveChages();
 
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