RadAsyncUpload - Cannot find the temporary file

18 posts, 1 answers
  1. Edwin
    Edwin avatar
    6 posts
    Member since:
    Jun 2012

    Posted 06 Jun 2012 Link to this post

    Dear telerik team,

    I've some problem using RadAsyncUpload [Q2 2010 .Net 3.5].
    When I want to save uploaded file to the specified folder, sometime it raised error exception: cannot find [temporary file location].  You can see error message on the pic attached.

    This problem doesn't always occur, means sometime I can successfully save the file.
    Below is my code when for saving the file:

    If RadAsyncUpload1.UploadedFiles.Count > 0 Then     
        For Each validFile As UploadedFile In RadAsyncUpload1.UploadedFiles 
            Dim targetFolder As String = Server.MapPath("~/uploadedFile/")
             
            If Not Directory.Exists(targetFolder) = True Then
                Directory.CreateDirectory(targetFolder)
            End If
     
            validFile.SaveAs(Path.Combine(targetFolder, validFile.FileName), True)
        Next
    End If

    Thank you..
  2. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 11 Jun 2012 Link to this post

    Hi Edwin,

    I reviewed the screenshot. Could you please check the temporary folder for the mentioned file when the exception is thrown.
    When a file is uploaded by the RadAsyncUpload control it is placed in a temporary folder. After a certain time (by default 4 hours) the files from the temporary folder are deleted by the asp.net framework. If the TemporaryFileExpiration property is set the expiration time will be different and it is possible the files to be deleted before your logic after the postback is applied and that should be causing the sporadic throwing of exceptions.

    Regards,
    Peter Filipov
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Edwin
    Edwin avatar
    6 posts
    Member since:
    Jun 2012

    Posted 11 Jun 2012 Link to this post

    Hi Peter,

    I monitored the temporary folder, and it seems the temporary files wasn't created when the exception occur. Is it possible RadAsyncUpload not create the temporary file because I put it on <asp:updatePanel> tag? Or should I set the expiration time using TemporaryFileExpiration property? Since currently I didn't set it..

    FYI, you could find my current application structure below. Maybe it could help to solve the problem:

    Master Page:
    <MasterPage>
      
        <asp:UpdatePanel>
            <asp:ContentPlaceHolder ID="MainContentPlaceHolder" runat="server">
     
                 [Form1.aspx]
      
             </asp:ContentPlaceHolder>
        </asp:Updatepanel>
      
    </MasterPage>

    Form1.aspx:
    <asp:Content ID="ca_form" ContentPlaceHolderID="MainContentPlaceHolder" runat="Server">
     
        [UserControl1.ascx]
        [UserControl2.ascx]
        [Attachment.ascx]
     
    </asp:Content>

    Attachment.ascx:
    <div class="attachment">
     
        <telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server">
        </telerik:RadAsyncUpload>
     
    </div>
  5. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 13 Jun 2012 Link to this post

    Hello Edwin,

    I setup a sample project from the provided structure and everything works fine at my side. Could please confirm that you found a pattern to reproduce the issue. If yes, please send me your project to test it locally.

    Regards,
    Peter Filipov
    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.
  6. Edwin
    Edwin avatar
    6 posts
    Member since:
    Jun 2012

    Posted 19 Jun 2012 Link to this post

    Hi Peter,

    After some testing, I found some pattern when the error occur:
    1. When I'm debugging
    2. When the page do postback, before the file to be attached was selected.

    In few days, I'll send you my project so you could test it locally.

    Thank you for your assistance :)
  7. Angel
    Angel avatar
    1 posts
    Member since:
    Jul 2010

    Posted 20 Jun 2012 Link to this post

    Hello,

    I'm having the same problem, cannot find the temporal file but only with IE8 Browser, everything it's working fine with Chrome, Firefox, etc.

    The only one that is not creating the temporal file is IE8, I'm using the last controls that comes with Sitefinity 5.0.

    Regards.

  8. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 22 Jun 2012 Link to this post

    Hello,

    We still can not reproduce the issue at our side and we are waiting for Edwin's sample.
    @Angel If you have a pattern to reproduce the issue try to set DisablePlugins property to true and test your project. Also if it is suitable for you please send me an example that reproduces the issue.

    All the best,
    Peter Filipov
    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.
  9. Edwin
    Edwin avatar
    6 posts
    Member since:
    Jun 2012

    Posted 09 Jul 2012 Link to this post

    Hi Peter,

    I apologise for the delay, little bit busy this 2 weeks..
    err.. how could i attach my sample project? Its size is 6MB after being zipped x___x

    hehe.. thank you
  10. Edwin
    Edwin avatar
    6 posts
    Member since:
    Jun 2012

    Posted 09 Jul 2012 Link to this post

    Peter,

    I just found an abnormality when I upload file using RadAsyncUpload.
    The case is the temporary file is automatically gone after few second (maybe about ten seconds), and it always happened.

    Maybe this is the root cause of my problem??

    below is my code for the attachment page:
    <telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server" TemporaryFileExpiration="00:30:00"
    OverwriteExistingFiles
    ="true" AllowedFileExtensions="pdf" MaxFileSize="500000">
    </
    telerik:RadAsyncUpload>
  11. Answer
    Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 10 Jul 2012 Link to this post

    Hi Edwin,

    The problem is related to the version that you are using, i.e. it is fixed for later version. Please either follow the workaround explained in this sticky thread (the Q2 2010 (Version 2011.2.713) section) or upgrade to a newer version of AJAX suite.

    Kind regards,
    Genady Sergeev
    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.
  12. Edwin
    Edwin avatar
    6 posts
    Member since:
    Jun 2012

    Posted 12 Jul 2012 Link to this post

    Dear Peter & Genady,

    I've updated my telerik version and right now the problem has been solved.

    Thank's for your support :)


    Kind Regards,
    Edwin K
  13. Zion
    Zion avatar
    1 posts
    Member since:
    Nov 2011

    Posted 21 Jan 2013 Link to this post

    Hello Dear Telerik  Team,
    We have the same issue as "Edwin" , and we are using the last Build of Telerik UI (2012.1.201.40).
    Please help us, we are trying to upload a file on our webform (ASP.NET 4).
    Than when we are trying to file.SaveAs(path...) we are getting this error.

    Its appears all the time, constantly.


    This is the code:
     <telerik:RadAsyncUpload ID="rdUploadedDocs" enablefileinputskinning="True"
                                                                    runat="server" MaxFileInputsCount="3" AllowedFileExtensions=".pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.jpeg,.jpg,.tif,.gif"
                                                          TargetFolder="~/Files/"   TemporaryFolder="~/Temp_Files" OnClientValidationFailed="validationFailed"
                                                           ControlObjectsVisibility="RemoveButtons,AddButton"  MaxFileSize="1500000" />

    Thanks,


  14. Plamen
    Admin
    Plamen avatar
    2730 posts

    Posted 24 Jan 2013 Link to this post

    Hello Zion,

     
    You can try to get the file by using this code:

    protected void RadAsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
    {
        string targetFolder = RadAsyncUpload1.TargetFolder;
        Response.Write(Server.MapPath(targetFolder + "/" + e.File.FileName));
        
    }

    Hope this will be helpful.

    Regards,
    Plamen
    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.
  15. jophy
    jophy avatar
    4 posts
    Member since:
    Jan 2014

    Posted 09 Oct 2014 in reply to Genady Sergeev Link to this post

    I have the same issue and i am adding the custom handler to set expiration time to avoid the issue (temp files deleted early)

    But, i would like to recheck in the server side if file exists in temporary folder before saving it.
    Is it possible to add checking in Uploadedfilescollection. How do we access full path of temporary file here?

    foreach (UploadedFile NewFile in AsyncUpload1.UploadedFiles)
    {
    string strPath = Server.MapPath(AsyncUpload1.TemporaryFolder);
    FileInfo file = new FileInfo(strPath + "\ + NewFile.FileName);
    if(File.Exists(file))
    {
    \\ This doesn't work,. Gives me the uploaded file name not the temp file name. But, i could see it in input stream and not able to access it.


    }

    Please help.
  16. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 10 Oct 2014 Link to this post

    Hi jophy,

    File will be removed from the temporary folder if:
    - you use FileSave() method.
    - it expires. The default expire time is 4 hours and it can be increased.
    - the Application pool is recycled. 

    Here is how you can check whether the file exists:

    Handler.ashx
    <%@ WebHandler Language="C#" Class="Handler" %>
     
    using System;
    using System.Web;
    using Telerik.Web.UI;
    using System.Data;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Data.SqlClient;
    using System.IO;
     
    public class Handler : AsyncUploadHandler, System.Web.SessionState.IRequiresSessionState
    {
        protected override IAsyncUploadResult Process(UploadedFile file, HttpContext context, IAsyncUploadConfiguration configuration, string tempFileName)
        {
            if (file != null)
            {
                 
            }


    Regards,
    Hristo Valyavicharski
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  17. jophy
    jophy avatar
    4 posts
    Member since:
    Jan 2014

    Posted 13 Oct 2014 Link to this post

    Thanks !! you are right !

    1. I used File.save as method both in FileUploaded method and Submit button postback which caused it.
    So, I am saving to target folder from submit click and not using uploaded event anymore. This is because I need to do some steps before saving files to target folder.

    2. Default expiration doesnot work in ie 8 and I have fixed it by setting this property.

    3. I tried your method to check if file exists but its called only in client side upload not after postback.
    I am trying to recheck these files incase there is a app pool recycle happened or any other file issue before proceeding to save to target folder.
    I tried below, but, it caused error file used by another process later when file is saved to target folder. 

       foreach (UploadedFile file in AsyncUpload1.UploadedFiles)
    {
    try
    {
    using (Stream stream = file.InputStream)
    {
    byte[] imageData = new byte[stream.Length];
    stream.Read(imageData, 0, (int)stream.Length);
    if (imageData.Length == 0)
    {
    isFileAvailable = false;
    }
    }
    }
    catch
    {
    isFileAvailable = false;
    }
    finally
    {
    file.InputStream.Close();
    file.InputStream.Dispose();
    }
    if (!(isFileAvailable))
    {

    RadAjaxManager1.Alert("Please upload the images again.");
    return;
    }
    }

    Is there a better way to do this check?

  18. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 16 Oct 2014 Link to this post

    This approach is good enough, but you may extend it with File.Exists() method to check if the file exists physically before you save it.

    It doesn't matter what browser you use. The default File Expiration time is 4 hours. It uses the Application Cache (in IIS), not the browser.

    Regards,
    Hristo Valyavicharski
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  19. Johann
    Johann avatar
    3 posts
    Member since:
    Jan 2015

    Posted 12 Feb 2015 Link to this post

    Hi, 

    Try This.

    foreach(UploadedFile file in rauUploadFiles.UploadedFiles)
     {
         FileStream tmpFile = (FileStream) file.InputStream;
    List<String> currentImages = Directory.GetFiles(HttpContext.Current.Server.MapPath("~/temp")).Where(f => f.Equals(tmpFile.Name)).ToList();

     }
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017