Getting Uploadify Working in C#

JoshSpacher picture JoshSpacher · Mar 23, 2010 · Viewed 16.1k times · Source

This seemed like it should be easy, but I have had trouble getting it to work. I don't know why it doesn't. It is just showing the normal file input.

Is there any code / examples to get this working. I am getting frustrated...

Thank you all.

Answer

Jason picture Jason · Mar 23, 2010

This is a video tutorial on how to get started using C# and Webforms, should help you.

http://casonclagg.com/articles/6/video-tutorial-uploadify-asp-net-c-sharp.aspx

Can you post your code though so that I might be able to show you what you are doing wrong?

Here is the sample code I have for asp.net

<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" />

Then you want to make a Handler (.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");
        }
    }
}

Post your code and I will take a look at it. Sounds like you are pointing to a resource that doesn't exist. Maybe your 'uploader' property is not pointed to the proper resource or your jquery link is broken (or not there).