Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
Hi
I have the below code and when I want to debug my handler it gives me "nullreferenceexception was unhandled by user code"

my handler fileis under my project folder and my javascript file which is the code below is in a subfolder of my project

Can anybody help me solve this problem?
C#
var xhr;
xhr = new XMLHttpRequest();

xhr.open('POST', 'FileUploadHandler.ashx.cs', true);
xhr.setRequestHeader('X_FILE_NAME', fileName);
xhr.setRequestHeader('Content-Type', fileType);
xhr.send(blob);
Posted
Comments
F-ES Sitecore 26-Aug-15 7:54am    
If you're trying to upload a file to your handler you can't do it like that. Google "html5 file api upload file" for proper examples.
Lalyka 26-Aug-15 8:09am    
I have done the same
// Uploading - for Firefox, Google Chrome and Safari
xhr = new XMLHttpRequest();
xhr.open("post", "upload/upload.php", true);

// Set appropriate headers
xhr.setRequestHeader("Content-Type", "multipart/form-data");
xhr.setRequestHeader("X-File-Name", file.name);
xhr.setRequestHeader("X-File-Size", file.size);
xhr.setRequestHeader("X-File-Type", file.type);

// Send the file (doh)
xhr.send(file);
F-ES Sitecore 26-Aug-15 8:27am    
Google html5 file api, you'll find examples of chunking files in there too. Basically what I'm saying is that this stuff is all very well documented already so rather than posting your question and asking for solutions, it is far quicker to use google to find articles that have all the code you need already written.
Richard Deeming 26-Aug-15 9:24am    
A NullReferenceException will be coming from your server-side code. You've only shown the client-side code, so we can't tell you what's causing it.

Click on the green "Improve question" link, and add the relevant parts of your server-side code, along with an indication of which line is throwing the exception.

Alternatively, use the debugger to step through your server-side code. You'll soon see which variable is causing the problem.
[no name] 27-Aug-15 18:39pm    
You should be checking all variables before assuming its not null. Alternatively, if you know what your code is doing, you should be able to predict any exceptions which will arise from user-code and thus the benefits of using catch exception blocks on code which you expect to be problematic. What you posted above does not reflect anything to pinpoint an issue. Please improve your question and I will be happy to help you.

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