Telerik RadAsyncUpload Event OnFileUploaded

http://www.telerik.com/help/aspnet-ajax/asyncupload-overview.html

RadAsyncUpload relies on saving temporary files to work. When posted, files are saved to the designated temp folder (App_Data/RadUploadTemp by default) with unique names.Once a postback occurs the RadAsyncUpload fires theOnFileUploaded event for each file. The target file is passed as part of the arguments to the event and can be set as either valid (default) or invalid. After the events fire, all files marked as valid are automatically saved to the TargetFolder if it’s set.

Finally, all processed temporary files are deleted. Temporary files are also deleted after a set amount of time defined by the TemporaryFileExpiration property.


TemporaryFileExpiration 

Note that when a postback occurs temporary files are either saved as permanent or removed.The expiration time is used only in cases when files are uploadedasynchronously, but a subsequent postback does not occur.

Sample

Default.aspx

<telerik:RadAsyncUpload runat="server" ID="RadAsyncUpload1" OnClientFileUploaded="onClientFileUploaded"
        TemporaryFileExpiration="00:01:00"  OnFileUploaded="RadAsyncUpload1_FileUploaded"  AllowedFileExtensions=".jpg" PostbackTriggers="RadButton1" Skin="Default"/>
     <telerik:RadButton runat="server" ID="RadButton1" Text="Submit your picture and information"
               OnClick="RadButton1_Click"  AutoPostBack="false" OnClientClicked="updatePictureAndInfo" Skin="Default" />

<script type="text/javascript">
         //<![CDATA[
    var $ = $telerik.$;

    function onClientFileUploaded(sender, args) {
        
    }

    function updatePictureAndInfo() {
            __doPostBack('RadButton1', '');
    }
        //]]>
        </script>

Default.aspx.cs

        protected void RadButton1_Click(object sender, EventArgs e)
        {
            
        }

        protected void RadAsyncUpload1_FileUploaded(object sender, Telerik.Web.UI.FileUploadedEventArgs e)
        {
            foreach (UploadedFile file in RadAsyncUpload1.UploadedFiles)
            {
                byte[] bytes = new byte[file.ContentLength];
                file.InputStream.Read(bytes, 0, file.ContentLength);
                //Insert bytes Into DB
                int i = 2;
            }
        }


Q & A:

1. RadUploadTemp folder not getting cleaned up

http://www.telerik.com/community/forums/aspnet-ajax/async-upload/raduploadtemp-folder-not-getting-cleaned-up.aspx

"Edit: Now I realise that all documents not getting cleand up have a corresponding entry in application log with this warning:"

Process information: 
    Process ID: 5076 
    Process name: w3wp.exe 
    Account name: NT AUTHORITY\NETWORK SERVICE 
 
Exception information: 
    Exception type: IOException 
    Exception message: The process cannot access the file 'C:\Apps\405000\WebSites\PublicWeb\App_Data\RadUploadTemp\1328611694996CVMYDOC-En.pdf' because it is being used by another process. 

Answer:

Your error log provides the exact reason why some of your files are not deleted:
Exception information: 
    Exception type: IOException 
    Exception message: The process cannot access the file 'C:\Apps\405000\WebSites\PublicWeb\App_Data\RadUploadTemp\1328611694996CVMYDOC-En.pdf' because it is being used by another process.


As it appears at the time when your temporary files should be removed, there is some process which is using them.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值