Custom File Drop (From Temporary - ToTarget Folder)

5 posts, 0 answers
  1. Haluk
    Haluk  avatar
    3 posts
    Member since:
    Aug 2013

    Posted 25 Sep 2013 Link to this post

    Hi,

    AsyncUpload Control  drop (carry) uploaded image file from "TemporaryFolder" to "TargetFolder" when any postback.

    I want to control this drop fonction. I think a functionality like :   AsyncUpload1.AutoDrop = False;    And   AsyncUpload1.Commit();   

    For ex:   error occurs when I run this code

    1. I choose a image file via AsyncUpload 
    2. AsyncUpload  upload Image File to Temprorary folder
    3. I click to btn1  (I try to get Image File  Data in this moment and delete image file from Temp Folder after my process ) 
    4. Error occurs


    Do you have a solution for this scenario?


    Could not find file 'D:\PRO\XBonWebSite\Co\Images\Test\Test\13801147907892e4jam1.jpg'.




        <asp:Panel ID="pnl1" runat="server">
            <asp:Label ID="lbl1" runat="server" Text="xx"></asp:Label>
            <telerik:RadAsyncUpload ID="AsyncUpload1" runat="server" OnFileUploaded="AsyncUpload1_FileUploaded" MaxFileSize="2097152" AllowedFileExtensions="jpg,png,gif"   AutoAddFileInputs="false" Localization-Select="Resim Ekle" Localization-Remove="Sil" TargetFolder="~/Co/Images/Test/Org/" TemporaryFolder="~/Co/Images/Test/Test/" HttpHandlerUrl="~/Co/Handlers/TelerikAsyncUploadHandler.ashx">
         </telerik:RadAsyncUpload>
        </asp:Panel>
        <asp:Button ID="btn1" runat="server" Text="btn1" OnClick="btn1_Click" />




      protected void Page_Load(object sender, EventArgs e)
        {
            lbl1.Text = DateTime.Now.ToString();
        }
        
    protected void btn1_Click(object sender, EventArgs e)  
        {      
           var len = AsyncUpload1.UploadedFiles[0].InputStream.Length;    
        }

        
    protected void AsyncUpload1_FileUploaded(object sender, Telerik.Web.UI.FileUploadedEventArgs e){
            lbl1.Text +=
    " FileUploaded";  
        }





  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 26 Sep 2013 Link to this post

    Hi Haluk,

    I assume that you are trying to access the ContentLength of the uploaded file. Please take a look into the following code snippet that I tried.

    C#:
    protected void btn1_Click(object sender, EventArgs e)
    {
        var length = AsyncUpload1.UploadedFiles[0].ContentLength;
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Haluk
    Haluk  avatar
    3 posts
    Member since:
    Aug 2013

    Posted 26 Sep 2013 Link to this post

    Thanks Shinu,  

    In fact it was only  example.  Already I can take some properties of the file such as   AsyncUpload1.UploadedFiles[0].FileName;  OR   AsyncUpload1.UploadedFiles[0].ContentType;    at Button1_Click event.  But  AsyncUpload1.UploadedFiles[0].InputStream  object not available here because the file moved from temp folder to target folder by RadAsyncUpload. And I take error ;  "Could not find file 'D:\XBonWebSite\Co\Images\Test\Test\138018175085315102010090.jpg'"

    D:\XBonWebSite\Co\Images\Test\Test  = Temporary Folder
    D:\XBonWebSite\Co\Images\Test\Org  =  Target Folder 

    Why do asyncupload  move uploaded file from temp to target at any postback?   Can't I control this moving process?

    I want to make this ;
     
    protected void Button1_Click(object sender, EventArgs e)
        {
            
    using (Stream stream = AsyncUpload1.UploadedFiles[0].InputStream)
            {
                
    byte[] imgData = new byte[stream.Length];
                stream.Read(imgData, 0, imgData.Length);
                MemoryStream ms =
    new MemoryStream();
               ms.Write(imgData, 0, imgData.Length);<br><br><br>       
     }
           
        }


  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 27 Sep 2013 Link to this post

    Hi Haluk,

    You can use the InputStream property to access the content of the uploaded files without saving them into a temporary location. This property is useful when you want to insert the file into a database or process its content without saving.

    Thanks,
    Shinu.

  6. Haluk
    Haluk  avatar
    3 posts
    Member since:
    Aug 2013

    Posted 27 Sep 2013 Link to this post

    Thanks for answer.  

    My Solution;

    1. Remove this property:  TargetFolder="C:/x/y/x"  >  "RadAsyncUpload Control"  will not move uploaded file from TempFolder anymore,  automatically

    2. Add this code:  AsyncUpload1.PostbackTriggers = new string[] { "Button1" };  > "RadAsyncUpload Control" will throw "AsyncUpload1_FileUploaded" event only with Button1 postback.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017