Programatically setting TempDirectory ?

Last post 08-03-2011, 5:08 AM by Jeff. 7 replies.
Sort Posts: Previous Next
  •  07-25-2011, 8:53 AM 68848

    Programatically setting TempDirectory ?

    Dynamically setting the TempDirectory in the code behind does not work?
     
      this.Uploader1.TempDirectory = "~/temp/U1/T"; 
     instead of in the aspx page as TempDirectory="~/temp/U1/Tx"
     
    The temp directory will vary depending on the users login. It needs to be set dynamically in code? 
     
    http://ajaxuploader.com/document/index.htm#page=BeforeYouBegin.htm
     
    I tried just setting the tempdirectory on the server in pre-render  with no luck.
    I also tried to dynamically create the entire instance of the control but it failed to perform an upload because of not being able to load jquery?
     
       CuteWebUI.Uploader up = new Uploader();
                   up.TempDirectory = "~/temp/U1/T";
                   up.ID = "Uploader2";
                   up.CancelButtonID = "Uploader2Cancel";
                   up.ShowProgressBar = false;
                   up.ShowProgressInfo = false;
                   up.FileTooLargeMsg = "File is too large!";
                   up.MultipleFilesUpload = true;
                   up.UploadCompleted += new UploaderBatchEventHandler(Uploader1_UploadCompleted);
                   divUpload.Controls.Add(up);
    Any suggestions? - Thanks! 
  •  07-26-2011, 4:31 AM 68868 in reply to 68848

    Re: Programatically setting TempDirectory ?

    Hi paulg,
     
    You can set TempDirectory by the code below
     
    1. <%@ Page Language="C#" %>  
    2.   
    3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    4.   
    5. <script runat="server">  
    6.     protected override void OnInit(EventArgs e)  
    7.     {  
    8.         base.OnInit(e);  
    9.         Uploader1.TempDirectory = "~/temp/u2/";  
    10.     }  
    11.   
    12.     void InsertMsg(string msg)  
    13.     {  
    14.         ListBoxEvents.Items.Insert(0, msg);  
    15.         ListBoxEvents.SelectedIndex = 0;  
    16.     }  
    17.     void Uploader_FileUploaded(object sender, UploaderEventArgs args)  
    18.     {  
    19.         Uploader uploader = (Uploader)sender;  
    20.         InsertMsg("File uploaded! " + args.FileName + ", " + args.FileSize + " bytes.");  
    21.   
    22.         //Copys the uploaded file to a new location.  
    23.         //args.CopyTo("c:\\temp\\"+args.FileName);  
    24.         //You can also open the uploaded file's data stream.  
    25.         //System.IO.Stream data = args.OpenStream();  
    26.     }       
    27. </script>  
    28.   
    29. <html xmlns="http://www.w3.org/1999/xhtml">  
    30. <head runat="server">  
    31.     <title>Simple Upload</title>  
    32.     <link rel="stylesheet" href="demo.css" type="text/css" />  
    33. </head>  
    34. <body>  
    35.     <form id="form1" runat="server">  
    36.         <div class="content">  
    37.             <h2>  
    38.                 Simple Upload (Customizing the UI)  
    39.             </h2>  
    40.             <p>  
    41.                 A sample demonstrating how to customize the look and feel of file upload controls.  
    42.                 (Maximum file size: 10M).  
    43.             </p>  
    44.             <asp:Image runat="server" ID="Uploader1Insert" AlternateText="Upload File" ImageUrl="~/sampleimages/upload.png" />  
    45.             <asp:Panel runat="server" ID="Uploader1Progress" BorderColor="Orange" BorderStyle="dashed"  
    46.                 BorderWidth="2" Style="padding-right: 4px; padding-left: 4px; padding-bottom: 4px;  
    47.                 padding-top: 4px">  
    48.                 <asp:Label ID="Uploader1ProgressText" runat="server" ForeColor="Firebrick"></asp:Label>  
    49.             </asp:Panel>  
    50.             <asp:Image runat="server" ID="Uploader1Cancel" AlternateText="Cancel" ImageUrl="~/sampleimages/cancel_button.gif" />  
    51.             <CuteWebUI:Uploader runat="server" ID="Uploader1" InsertButtonID='Uploader1Insert'  
    52.                 ProgressCtrlID='Uploader1Progress' ProgressTextID='Uploader1ProgressText' CancelButtonID='Uploader1Cancel'  
    53.                 OnFileUploaded="Uploader_FileUploaded">  
    54.                 <ValidateOption MaxSizeKB="10240" />  
    55.             </CuteWebUI:Uploader>  
    56.             <br />  
    57.             <br />  
    58.             <div>  
    59.                 Server Trace:  
    60.                 <br>  
    61.                 <br>  
    62.                 <asp:ListBox runat="server" ID="ListBoxEvents" Width="400"></asp:ListBox>  
    63.             </div>  
    64.         </div>  
    65.     </form>  
    66. </body>  
    67. </html> 
     
    Hope it helps.
     
    Regards,
    Jeff
  •  07-26-2011, 8:46 AM 68881 in reply to 68868

    Re: Programatically setting TempDirectory ?

    Works great! Thanks!
  •  08-01-2011, 9:10 AM 69120 in reply to 68868

    Re: Programatically setting TempDirectory ?

    This did not work for me on the page_load however? Since init preceeds  viewstate loading of postback data I can not retrieve the information I need to properly identify the path to set? Any suggestions?
  •  08-01-2011, 10:36 AM 69126 in reply to 69120

    Re: Programatically setting TempDirectory ?

    I guess in practice absolute uniqueness  is not necessary and may be better if it's not done since the file itself appears to be unique coming from the ajaxuploader. I would be interested to know if there is a solution but it isn't absolutely essential.
  •  08-01-2011, 10:50 AM 69128 in reply to 69126

    Re: Programatically setting TempDirectory ?

    Hi paulg,
     
    Try set in your web.config
     
         <appSettings>
      <add key="CuteWebUI.AjaxUploader.TempDirectory" value="~/temp" /> 
        </appSettings>
     
    Regards,
     
    ken
  •  08-01-2011, 1:34 PM 69133 in reply to 69128

    Re: Programatically setting TempDirectory ?

    Maybe I'm not clear. It works on the init override but I wanted it to work on page load so I can customize the folder to the specific account. It occurs too early for that. A static isn't helpful in this regard either. If I just want a static tempdirectory the init or web config will work file. It would be advantageous to set the target folder but it's not critical. 
  •  08-03-2011, 5:08 AM 69214 in reply to 69133

    Re: Programatically setting TempDirectory ?

    Hi paulg,
     
     Its TempDirectory attribute can be set in Page Load event
    Please test the section code below
    1. protected void Page_Load(object sender, EventArgs e)  
    2. {  
    3.     Uploader1.TempDirectory = "~/temp/u3/";  
    4. }  
     
     
    Regards,
    Jeff 
View as RSS news feed in XML