Problem with uploading file when TargetFolder doesn't exist

Thread is closed for posting
3 posts, 0 answers
  1. Akki
    Akki avatar
    79 posts
    Member since:
    Nov 2011

    Posted 15 Mar 2012 Link to this post

    Hi,
    Any support on this ?  or no solution ??

    I am getting crash when the TargetFolder="~/MYFiles" doesn't exist.. I tried to see whether folder exist on button click
    but the crash appears before button click.. below is the code.

    Can u help me out, how to check wether targetfolder exist or not.

     <telerik:RadUpload ID="RadUpload1" runat="server"
            ControlObjectsVisibility="CheckBoxes, AddButton, DeleteSelectedButton"
            TargetFolder="~/MYFiles" onfileexists="RadUpload1_FileExists" OverwriteExistingFiles="false">
      </telerik:RadUpload>

    <asp:Button ID="btnUpload" runat="server" Text="Upload" onclick="btnUpload_Click"  />

    C#
     protected void btnUpload_Click(object sender, EventArgs e)
        {
            if (RadUpload1.UploadedFiles.Count > 0)
            {
                string filename = Path.GetFileName(RadUpload1.UploadedFiles[0].GetName());
                if (System.IO.Directory.Exists(Server.MapPath(RadUpload1.TargetFolder)))
                {
                }
                else
                {  
                }
            }
        }

    Regards,
    Akki
  2. Akki
    Akki avatar
    79 posts
    Member since:
    Nov 2011

    Posted 18 Mar 2012 Link to this post


    Any support on this ?  or no solution ??

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1266 posts

    Posted 21 Mar 2012 Link to this post

    Hi,

    The problem in your case is caused by the fact that the button click event is fired a bit late and the RadUpload had already tried to save the file in the target folder. Please find a sample page showing how to proceed in scenarios like yours.

    Greetings,
    Dimitar Terziev
    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