Iam using uploadify with http handler and sending data to handler but http context alway returning null value. Please help, here is the code:
<pre lang="cs">$('#fileUpload').uploadify({
'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 });
}
});
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;
}
}
}