Help with AsyncUpload vs Upload before i go nuts

3 posts, 0 answers
  1. Joshua
    Joshua avatar
    7 posts
    Member since:
    Oct 2011

    Posted 08 Dec 2011 Link to this post

    Below is the code i'm using and I'm have a few questions regarding whats happening.

    1) The file never actually saves, i click submit and it appears to work but the file never saves to my target directory.  How do I resolve this.
    2) When i try a second time to save a file i get directory access is denied, not sure what.
    3) when I use a HTML5 browser and the drag and drop functionality is present, i'm able to save to a test directory C:\test with whatever file I choose, however, when I use RadUpload (non HTML5) i keep getting physical error paths messages.  How do I resolve this?  I need to be able to save to a specific folder.
    var $ = $telerik.$;
         function pageLoad() {
             if (!Telerik.Web.UI.RadAsyncUpload.Modules.FileApi.isAvailable()) {
                 $(".wrapper").replaceWith(
                 $(""));
             }
         }
     
         function added(sender, args) {
             if (Telerik.Web.UI.RadAsyncUpload.Modules.FileApi.isAvailable()) {
     
                 $(".ruDropZone").html("<br /><div align=\"center\"><img src=\"images/toolboxdragdrop.jpg\"></div>");
                 $(".nonHTML5").replaceWith(
                 $(""));
             }
         }
          
     </script>
     
         <div class="wrapper">
             <telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server"
                 OnClientAdded="added" OnFileUploaded="RadAsyncUpload1_FileUploaded">
             </telerik:RadAsyncUpload>
             <telerik:RadProgressManager ID="Radprogressmanager1" runat="server" />
         </div>
         <div class="nonHTML5" style="position:relative;">
             <table>
                 <tr>
                     <td id="controlContainer">
                         <telerik:RadUpload ID="RadUpload1" runat="server" MaxFileInputsCount="5"
                             OverwriteExistingFiles="true" OnFileUploaded="RadAsyncUpload1_FileUploaded" />
                         <telerik:RadProgressArea ID="progressArea1" runat="server" />
                     </td>
                     <td>
                         <div class="smallModule">
                             <div class="rc1">
                                 <div class="rc2">
                                     <div class="rc3" style="width:240px">
                                         <asp:Label ID="labelNoResults" runat="server" Visible="True">No uploaded files yet</asp:Label>
                                         <asp:Repeater ID="repeaterResults" runat="server" Visible="False">
                                             <HeaderTemplate>
                                                 <div class="title">
                                                     Uploaded files in the target folder:</div>
                                             </HeaderTemplate>
                                             <ItemTemplate>
                                         <%#DataBinder.Eval(Container.DataItem, "FileName")%>
                                         <%#DataBinder.Eval(Container.DataItem, "ContentLength").ToString() + " bytes"%>
                                         <br />
                                             </ItemTemplate>
                                         </asp:Repeater>
                                     </div>
                                 </div>
                             </div>
                         </div>
                     </td>
                 </tr>
             </table>
         </div>
         <asp:Button ID="buttonSubmit" runat="server" CssClass="RadUploadSubmit"
             OnClick="buttonSubmit_Click" text="Submit" />
       </td>

    .aspx.cs
    public void RadAsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
        {
            RadAsyncUpload1.TargetFolder = MechanicToolboxClass.ToolBoxSaveToFolder();
        }
     
        protected void buttonSubmit_Click(object sender, System.EventArgs e)
        {
             
            if (RadUpload1.UploadedFiles.Count > 0)
            {
                TargetFolderUpload = MechanicToolboxClass.ToolBoxSaveToFolder();
                RadUpload1.TargetFolder = TargetFolderUpload;
                repeaterResults.DataSource = RadUpload1.UploadedFiles;
                repeaterResults.DataBind();
                labelNoResults.Visible = false;
                repeaterResults.Visible = true;
            }
            else
            {
                labelNoResults.Visible = true;
                repeaterResults.Visible = false;
            }
             
        }

  2. Joshua
    Joshua avatar
    7 posts
    Member since:
    Oct 2011

    Posted 08 Dec 2011 Link to this post

    This is what i've changed and it works, however, Is all of this necessary?  It's not possible to set the TargetFolder in behind code?  It seems even if I set the targetFolder in behind code it does not set it.

    It appears I want to use TargetPhysicalFolder, how do I see the TargetPhysicalFolder on the front end to be dynamic?

    aspx.cs
    TargetFolder="~/temp"/>

     
    public static string TargetFolderUpload (@"C:\test")

    protected void buttonSubmit_Click(object sender, System.EventArgs e)
        {
            
            if (RadUpload1.UploadedFiles.Count > 0)
            {
                TargetFolderUpload = MechanicToolboxClass.ToolBoxSaveToFolder();
                RadUpload1.TargetFolder = TargetFolderUpload;
                repeaterResults.DataSource = RadUpload1.UploadedFiles;
                repeaterResults.DataBind();
                labelNoResults.Visible = false;
                repeaterResults.Visible = true;
                FileMover(RadUpload1.UploadedFiles);
            }
            else
            {
                labelNoResults.Visible = true;
                repeaterResults.Visible = false;
            }
            
        }
     
    private void FileMover(UploadedFileCollection uploadedFileCollection)
        {
            foreach (UploadedFile uploadedFile in uploadedFileCollection)
            {
                File.Copy(@"C:\Websites\temp\" + uploadedFile.FileName,TargetFolderUpload+"\\"+uploadedFile.FileName);
                File.Delete(@"C:\Websites\temp\" + uploadedFile.FileName);
            }
        }

  3. Bozhidar
    Admin
    Bozhidar avatar
    1189 posts

    Posted 12 Dec 2011 Link to this post

    Hi Joshua,

    If you want to set the target folder dynamically with RadUpload, you need to set it earlier in the page lifecycle. Try setting it in the Page_Load event.

    Kind regards,
    Bozhidar
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top