This is a migrated thread and some comments may be shown as answers.

Custom File Drop (From Temporary - ToTarget Folder)

4 Answers 89 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Haluk
Top achievements
Rank 1
Haluk asked on 25 Sep 2013, 02:58 PM
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";  
    }





4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Sep 2013, 07:16 AM
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.
0
Haluk
Top achievements
Rank 1
answered on 26 Sep 2013, 08:01 AM
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>       
 }
       
    }


0
Shinu
Top achievements
Rank 2
answered on 27 Sep 2013, 05:33 AM
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.

0
Haluk
Top achievements
Rank 1
answered on 27 Sep 2013, 07:37 AM
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.
Tags
AsyncUpload
Asked by
Haluk
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Haluk
Top achievements
Rank 1
Share this question
or