Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Iam using uploadify with http handler and sending data to handler but http context alway returning null value. Please help, here is the code:

JavaScript
<pre lang="cs">$('#fileUpload').uploadify({
                    //'debug': true,

                    //PUBLISH MODE
                    //'swf': '/Platform/Scripts/Uploadify/uploadify.swf',
                    //'uploader': '/Platform/Scripts/Uploadify/uploadify.ashx',
                    //'cancelImg': '/Platform/Scripts/Uploadify/uploadify-cancel.png',
                    //DEBUG MODE
                    'swf': '/Scripts/Uploadify/uploadify.swf',
                    'uploader': '/Scripts/Uploadify/uploadify.ashx',
                    'cancelImg': '/Scripts/Uploadify/uploadify-cancel.png',

                    'fileTypeDesc': '*.pdf Files',
                    'fileTypeExts': '*.pdf',
                    'fileSizeLimit': '2MB',
                    'buttonText': 'Select Files',
                    'removeCompleted': false,
                    'multi': true,
                    'auto': false,
                    'data': { 'Ref': 'Test', 'Ordnum': 'NA', 'User': 'NA', 'SP': 'NA' },
                    'onUploadError': function (file, errorCode, errorMsg, errorString) {
                        alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
                    },
                    'onUploadStart': function (file) {
                        var ref = $("#podref_tb").val();
                        var ordnum = $("#soNumLBL").text();
                        var user = $("#hiddenUser").val();
                        var sp = $("#hiddenSP").val();


                        $('#fileUpload').uploadify("settings", 'data', { 'Ordnum': ordnum, 'Ref': ref, 'User': user, 'SP': sp });

                    }
                });


C#
public class uploadify : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                file_upload newfile = new file_upload();
                string strTest = context.Request["User"];
                newfile.user = context.Request["User"];
                newfile.sp = context.Request["SP"];

                if (newfile.user == "NA" | newfile.user == null | newfile.sp == "NA" | newfile.sp == null)
                {
                    throw new Exception("No user info");
                }

                HttpPostedFile postedFile = context.Request.Files["Filedata"];
                newfile.ordnum = context.Request["Ordnum"];
                newfile.delref = context.Request["Ref"];
                string savepath = "";
                string tempPath = "";
                tempPath = System.Configuration.ConfigurationManager.AppSettings["PODPath"];
                savepath = context.Server.MapPath(tempPath);
                string sguid = System.Guid.NewGuid().ToString();
                newfile.filename = sguid + "_" + newfile.ordnum + ".pdf";
                if (!Directory.Exists(savepath))
                {
                    throw new Exception("Problem with filepath");
                }

                postedFile.SaveAs((savepath + "\\") + newfile.filename);
                context.Response.Write((tempPath + "/") + newfile.filename);
                context.Response.StatusCode = 200;

                newfile.Save();
            }
            catch (Exception ex)
            {
                string error = "Error: " + ex.Message;
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
Posted

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