Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 1st, 2012  |  syntax: None  |  size: 1.67 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Ajax Control Toolkit AsyncFileUploader Control and viewstate/session Issue
  2. public partial class DesignUploader : System.Web.UI.UserControl
  3. {
  4.     private static readonly string AppDataPath = HttpContext.Current.Server.MapPath("~/App_Data/");
  5.  
  6.     public string FirstFilePath
  7.     {
  8.         get
  9.         {
  10.             return Server.UrlDecode( FirstFilePathHiddenField.Value);
  11.         }
  12.     }
  13.  
  14.     public string SecondFilePath
  15.     {
  16.         get
  17.         {
  18.             return Server.UrlDecode(SecondFilePathHiddenField.Value);
  19.         }
  20.     }
  21.  
  22.     protected override void OnInit(EventArgs e)
  23.     {
  24.         base.OnInit(e);
  25.  
  26.         FirstFileUpload.UploadedComplete += FirstFileUpload_UploadedComplete;
  27.         SecondileUpload.UploadedComplete += SecondileUpload_UploadedComplete;
  28.     }
  29.  
  30.     void FirstFileUpload_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
  31.     {
  32.         var fullPath = Path.Combine(AppDataPath, Path.GetFileName(e.FileName));
  33.         FirstFileUpload.SaveAs(fullPath);
  34.         SaveFilePathToHiddenField(FirstFilePathHiddenField.ClientID, fullPath);
  35.     }
  36.  
  37.     void SecondileUpload_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
  38.     {
  39.         var fullPath = Path.Combine(AppDataPath, Path.GetFileName(e.FileName));
  40.         SecondileUpload.SaveAs(fullPath);
  41.         SaveFilePathToHiddenField(SecondFilePathHiddenField.ClientID, fullPath);
  42.     }
  43.  
  44.     private void SaveFilePathToHiddenField(string fieldId, string pathValue)
  45.     {
  46.         var script = string.Format("top.$get('{0}').value = '{1}';", fieldId, Server.UrlEncode(pathValue));
  47.         ScriptManager.RegisterStartupScript(this, this.GetType(), "setPath", script, true);
  48.     }
  49. }