Oklahoma Software Consulting and Web Development Cason Clagg

Video Tutorial - Uploadify Control Using ASP.Net and C#

  • Mar 19, 2010 at 2:58 PM
  • 67 Comments

Edit: If this helped you and you want to repay the favor...

Vote for my wifes photo contest entry HERE

WATCH THIS TUTORIAL IN HD!

Here is a 15 minute explaination of how to use an Uploadify control in an ASP.Net application, using C#. It is a complete walkthrough, from downloading uploadify and opening VS2008 Web Express to setting some of the advanced uploadify options.

Instead of the Upload.php handler that is shown in the Uploadify examples online, we use a Generic Handler, Upload.ashx, to handle our upload logic.

It seems really easy to do in retrospect, but when you are sitting there with no example using your set of tools, it can be frustrating. Enter this video.

The following is the code I promised:

Uploadify Control:

<script type="text/javascript">
       // <![CDATA[
       var id = "55";
       var theString = "asdf";
       $(document).ready(function() {
       $('#fileInput').uploadify({
       'uploader': 'uploadify/uploadify.swf',
       'script': 'Upload.ashx',
       'scriptData': { 'id': id, 'foo': theString},
       'cancelImg': 'uploadify/cancel.png',
       'auto': true,
       'multi': true,
       'fileDesc': 'Image Files',
       'fileExt': '*.jpg;*.png;*.gif;*.bmp;*.jpeg',
       'queueSizeLimit': 90,
       'sizeLimit': 4000000,
       'buttonText': 'Choose Images',
       'folder': '/uploads',
       'onAllComplete': function(event, queueID, fileObj, response, data) {

       }
     });
   });
   // ]]></script>

   <input id="fileInput" name="fileInput" type="file" />

Upload.ashx

public class Upload : IHttpHandler, IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {
        try
        {
            HttpPostedFile file= context.Request.Files["Filedata"];

            int id = (Int32.Parse(context.Request["id"]));
            string foo = context.Request["foo"];
            file.SaveAs("C:\\" + id.ToString() + foo + file.FileName);

            context.Response.Write("1");
        }
        catch(Exception ex)
        {
            context.Response.Write("0");
        }
    }
}

Make a Comment

Name


Email


Comment


Comments

- By 1 Weeks Ago
- By 1 Weeks Ago
This is awesome dude!!!!!! thank you so much.... - By Edwin 1 Weeks Ago
It worked fine for me. it is really excellent. try my code if it does not work for u. my implementation code is available at http://go2amitech.blogspot.com/2010/08/asynchronous-file-upload-in-aspnet.html - By Amit Panchal 2 Weeks Ago
Great script works fine for me. Gives me an error while reading the value from the hidden variable.Please post the code related to the hidden variable if possible. - By .Net Developer 3 Weeks Ago
This looks awesome, but when I tried to impliment the very basic beginning all it did was break all my JQuery that already have working. I've tried everything, and pared your code down to the most basic elements and i can't figure out what it is, but it just breaks my existing JQuery. I am just hack at JQuery, just recently started, but my code works until I add yours. OK, I finally fixed or figured it out. I deleted line by line. if you leave the scriptdata line with no arguments in there it breaks the code. I'll move on in your tutorial. I am trying to convince myself that IQuery is the way to go, but I am not wrapping my head around how everything can't be done in the code behind in a language I know how to write? - By Earl 3 Weeks Ago
is that possible to implement script in .cs file? - By fr 3 Weeks Ago
Hey can you provide some help inputting the file url at SQL? - By Andrew G. 3 Weeks Ago
Nevermind to the question about invoking the upload if auto is set to false. Need have some jquery in place to invoke the upload method example...javascript:$('#fileInput').uploadifyUpload(); - By d 3 Weeks Ago
Hi there, This was an excellent tutorial and I was able to setup according to your video. My question is how would I go about invoking the upload process if I set the 'auto'property to be false? - By D 3 Weeks Ago
- By 3 Weeks Ago
Thanks! That makes it so much easier to understand.. paniced a little when saw it was PHP - By Bex 5 Weeks Ago
you're a slut and Im gonna fuck you - By 5 Weeks Ago
Very informative; thanks. I follow your example and it works fine locally; however, when I upload it to the server, I always get the uploadify HTTP 404 error that it cannot find the script Upload.ashx. My directory structure differs in that my aspx, ashx and uploadify folder are in a subfolder off the root, but that should not make a difference. I even moved the uploadify.ashx to the uploadify folder and changed the script: location to uploadify/upload.ashx, but I still get the error. Any ideas? - By Stephanie Lowery 6 Weeks Ago
- By 6 Weeks Ago
Thanks for your movie and code. This helps me a lot. I used forms authentication for my web application and having problem with the upload.ashx. The solution is to add the following code in web.confg, hope this will help other facing same problem as me <location path="Upload.ashx"> <system.web> <authorization> <allow users="*"/> </authorization> </system.web> </location> - By zayar 6 Weeks Ago
Thanks for your movie and code. This helps me a lot. I used forms authentication for my web application and having problem with the upload.ashx. The solution is to add the following code in web.confg, hope this will help other facing same problem as me %3Clocation%20path%3D%22Upload.ashx%22%3E%0A%20%20%20%20%3Csystem.web%3E%0A%20%20%20%20%20%20%3Cauthorization%3E%0A%20%20%20%20%20%20%20%20%3Callow%20users%3D%22*%22%2F%3E%0A%20%20%20%20%20%20%3C%2Fauthorization%3E%0A%20%20%20%20%3C%2Fsystem.web%3E%0A%20%20%3C%2Flocation%3E - By zayar 6 Weeks Ago
这个确实很好用,但是我遇到了一个问题。buttonText的值不能是中文,这样会乱码。请问怎么解决? 改成图片显示呗。。图片上显示中文就可以了 - By 6 Weeks Ago
Thanks sir..... - By Kumar 6 Weeks Ago
这个确实很好用,但是我遇到了一个问题。buttonText的值不能是中文,这样会乱码。请问怎么解决? - By 峰 7 Weeks Ago
Cason Thanks for this excellent example - awesome! Cheers Jim - By Jim 7 Weeks Ago
Hello, Congratulations!!! You used the Upload.ashx to the 'script'. Do you have the example .ashx for 'checkScript'? Thanks! - By Vivian 7 Weeks Ago
hello sir. It is great script. i have tried in my application. but when i try to save file in my application. it gibes me error. could not find the path. i tried many thing but still give me the same error. so please tell me how to solve this issue. Thanks in Advance Omkar - By Omkar Mhaiskar 7 Weeks Ago
Thank you, it works fine. How can i send/get data from textbox, just like you did with the Hiddenfiled. textbox id="UserName"? - By izy@htb.co.il 7 Weeks Ago
- By 7 Weeks Ago
Is it possible to post up a WCF version of implementation? It will be really great since Microsoft is making WCF as the major of web service provider framework. - By 8 Weeks Ago
- By 9 Weeks Ago
- By 10 Weeks Ago
- By 11 Weeks Ago
- By 11 Weeks Ago
This is really great. but I'll like to know if this can be used in case where the upload is to SQL Server database and not to server file path. Really appreciate any help on how to make it work with SQL Server uploads. Thanks. ebot64@yahoo.com - By Tobe Eze 11 Weeks Ago
fsdfsdf - By 12 Weeks Ago
Hi All, This aplication is very usefull but when upload is finished I need to get the name of the file. Because after upload is finished I have save to DB name of the file. How can I get the name? Thanks. - By Ufuk 13 Weeks Ago
your code is right. but there are some problem while running this program. i upload the file then a problem occure http error and io error. - By Atul Singhal 13 Weeks Ago
very easy to implement, but will it work in asp.net2.0 also can we set 'fileExt' and 'folder' dynammicaly ??? - By Nikeeta Vanjara 15 Weeks Ago
Hi Kumiko (2 comments down), Yes, you can implement in vb.net. - By Jinho 15 Weeks Ago
I'm not able to view Vimeo, youtube or any of the "popular" video sites at work =( - By Kode 16 Weeks Ago
Awesome article! Is there any way to style the upload button? The .css file only appears to have style info for QueueItem's. Thanks! - By David 16 Weeks Ago
hi, this is a good sample. by the way, is it can implement with the asp.net vb.net ?thank you. - By kumiko 16 Weeks Ago
- By 17 Weeks Ago
- By 17 Weeks Ago
Meal Network,until move however slip session advance peace suggest typical involve win television very birth just clothes effective sing milk hole expert reduce active rather interested wash communication whom chapter except establish once concept drive achieve always beneath east factor anyone capacity council statement home do objective confidence budget notion attractive appearance train survive dress civil water existence noise fast campaign reader carry through different pattern association impossible spring cold lead head off oil study clean lunch provided result thought around essential criminal bloody - By hotel buchen niederlande 17 Weeks Ago
Make sure you don't delete the bool isReusable() {...} or whatever it is when you make your new Handler. It has to be in there for the Handler to work. - By Cason Clagg 17 Weeks Ago
When you set the sizeLimit, is that enforced before the upload begins or after it has been uploaded? - By rw 18 Weeks Ago
提示http error,你的Upload.ashx太简单了吧 - By 哥斯拉 18 Weeks Ago
anyone tried using this on forms authentication? - By Joel 18 Weeks Ago
For those of you wondering how to redirect after the upload is complete...I do it by having JQuery/Javascript click a button in the onAllComplete() and then just use code-behind for that button to do logic/Response.Redirect("wherever.aspx", false).... I'm pretty sure I did this in the video. If not I'll add something to the code above. - By Cason Clagg 18 Weeks Ago
hi, uploadify seem to be having problem when in forms authentication... any work around for that? - By Joel 19 Weeks Ago
it all works fine but i have a problem its not show be the uploading progress i have just the button once i choose the image it save it but without any animation thing happen even i can't see the cancel button what am i suppose to do - By Ahmed 19 Weeks Ago
hi, Its not working with mozilla and later IE. Can any one help? its working with IE 6.0. and sometimes its not showing button there? - By darshan 20 Weeks Ago
Muy buen tutorial, gracias por compartirlo! Excelent video! Thanks for sharing - By daniel 20 Weeks Ago
Thanks for sharing this, a real kick start in the right direction! - By Andreas 20 Weeks Ago
I need the demo! please!! - By 天堂 20 Weeks Ago
Thanks for the great tutorial. Though you have mis-lead people on one thing. ASP.Net application this is not a Application, this is a ASP.Net Web Site. Please correct this in your description. Other than that one mistake, this is a good tutorials and very informative. Wayne - By Wayne 20 Weeks Ago
Just for the record: 'onAllComplete': function(event, queueID, fileObj, response, data) { alert(fileObj.name); } Cafc - By cafc 21 Weeks Ago
hi great job! i need to get filename after the upload but when i do this : var file_name = document.getElementById("fileInput").value; it doesn't work. Can you help me, please ! i really need this. thanks in advance cafc - By cafc 21 Weeks Ago
Nice Job, it was very helpful. Thank you for the quick and clear explanation for how this control works with asp.net. - By 21 Weeks Ago
Great work with the example and video. This was very helpful in getting this sample up and running. I would like to check a user is logged in first before allowing a posting using something like: if (context.User.Identity.IsAuthenticated == true) on the handler page. How could I do a redirect after determining the user is not authenticated? Thanks, Robin. - By Robin 21 Weeks Ago
Awesome video, very helpful. I wish everyone did this. I am going to put the code in my site www.prop2go.com later today. thanks, Jaosn - By Jason 21 Weeks Ago
- By 22 Weeks Ago
how to redirect new page after completion of files upload? - By sravan 22 Weeks Ago
Its not working with jQuery lightbox. - By sravan 22 Weeks Ago
Apologies - Feel like a dunce - after hours of code checking and re-checking - it was the version of FlashPlayer on my pc - I had fidbg10.ocx - installed the latest (flash10e.ocx ) and it all works just great - many many thanks - By Kevin Kidson 22 Weeks Ago
Sounds like JQuery is messed up in IE for you maybe? - By Cason Clagg 22 Weeks Ago
Yes I did. Works fine in IE6 for me. Email me exactly what you have and I'll take a look at it. - By Cason Clagg 22 Weeks Ago
Great bit of work - I have it working just fine in FireFox, but in IE the browse button does not show. It has something to do with #fileInput - Did you test in IE? - By Kevin Kidson 22 Weeks Ago
- By 22 Weeks Ago
I am a freelance software and web developer that specializes in the development of custom online applications, search engine optimization, social media and anything .NET.

Current Project

CarYelp
© Cason Clagg 2010