2013-10-16 61 views
0

嗨,我一直在試圖設置了一個param傳遞給我的ashx頁的年齡Ajaxupload.js如何通過查詢參數來ASHX文件asp.net

預先感謝您

我目前使用此設置

upload

其使用

jQuery的存在從安德里斯Valums 插件你

代碼示例

<script type="text/javascript"> 
$(function() { 
     var customerID = getURLParameter("id"); 
     new AjaxUpload('#UploadButton', { 
      action: 'UploadHandler.ashx', 
      data: { "customerID":"44455" }, 
      onComplete: function (file, response) { 


       $('#UploadStatus').html("<div class=success>file has been uploaded sucessfully</div>"); 
       $("#UploadButton").hide(); 
      }, 
      onSubmit: function (file, ext) { 
       if (!(ext && /^(jpg|png)$/i.test(ext))) { 
        alert('Invalid File Format.'); 
        return false; 
       } 
       //$('#UploadStatus').html("Uploading...");    
      } 
     }); 

    }); 
</script> 

HTML側

<input type="button" id="UploadButton" class="btnReg charcoal" value="Upload Image" /> 

ASHX側

public void ProcessRequest(HttpContext context) 
    { 
     folderPath = HttpContext.Current.Server.MapPath("DownloadedFiles"); 
     customerID = context.Request.QueryString["customerID"]; 

     //Uploaded File Deletion 
     if (context.Request.QueryString.Count > 0) 
     { 
      string filePath = folderPath + "//" + context.Request.QueryString[0].ToString(); 
      deleteIMG(filePath, context.Request.QueryString[0].ToString()); 
     } 
     //File Upload 
     else 
     { 
      //check if directory exist if not create one 
      var ext = Path.GetExtension(context.Request.Files[0].FileName); 
      var fileName = Path.GetFileName(context.Request.Files[0].FileName); 

      if (context.Request.Files[0].FileName.LastIndexOf("\\") != -1) 
      { 
       fileName = context.Request.Files[0].FileName.Remove(0, context.Request.Files[0].FileName.LastIndexOf("\\")).ToLower(); 
      } 

      fileName = GetUniqueFileName(fileName, HttpContext.Current.Server.MapPath("DownloadedFiles/"), ext).ToLower(); 

      string location = HttpContext.Current.Server.MapPath("DownloadedFiles/") + fileName + ext; 
      context.Request.Files[0].SaveAs(location);    

      context.Response.Write(fileName + ext); 
      context.Response.End();    
     } 

    } 

回答

1

它已經一段時間,因爲我用它,但我認爲它做了POST並且要能夠讀取您的處理程序中的這些參數,您需要從

context.Request.Params["paramname"] 
+0

非常感謝你 – Neo

相關問題