Problem using RadAsyncUpload

Thread is closed for posting
5 posts, 0 answers
  1. Rajiv Prashant
    Rajiv Prashant avatar
    16 posts
    Member since:
    Oct 2009

    Posted 14 Sep 2010 Link to this post

    When i use RadAsyncUpload and Rad Upload its giving the following error

    Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: The process cannot access the file because it is being used by another process.



    I have pasted the code for your reference.


        protected void AsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
        {

            checkThum.Width = Unit.Pixel(97);
            checkThum.Height = Unit.Pixel(60);
            if (e.File.FileName.Length <= 150)
            {
                byte[] imageData = new byte[e.File.InputStream.Length];

                using (Stream stream = e.File.InputStream)
                {
                    stream.Read(imageData, 0, (int)e.File.InputStream.Length);
                }

                checkThum.Visible = true;
                checkThum.DataValue = imageData;

            }
            else
            {
                checkThum.Visible = false;

            }

        }


    The above is the code where i will read it as bytes and display the image.




      protected void Button1_Click(object sender, EventArgs e)
        {
            if (RadUpload1.UploadedFiles.Count > 0)
            {
                if (AsyncUpload1.UploadedFiles.Count > 0)
                {
                    AsyncUpload1.TargetFolder = System.Configuration.ConfigurationSettings.AppSettings["NetworkSmallImageUrl"];
                    UploadedFile ufImage = AsyncUpload1.UploadedFiles[AsyncUpload1.UploadedFiles.Count - 1];

                    string imgFileNameMaster = DateTime.Now.TimeOfDay.Ticks.ToString() + ufImage.FileName;
                    string strImgPathMaster = System.Configuration.ConfigurationSettings.AppSettings["NetworkSmallImageUrl"] + imgFileNameMaster;
                    string FolderPathMaster = Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings["NetworkSmallImageUrl"]) + imgFileNameMaster;
                    new PictureFunctions().IsResizeRadUploadImageWithWhiteBackroundFilled(ufImage, FolderPathMaster, 80, 56);

                    ViewState["LogoPath"] = strImgPathMaster;

                }
    }
    }

    The above is the button click event which is hidden when i choose a file from a Radupload this button1_click will be fired.


    Can you guys help me out on this issue.



  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 17 Sep 2010 Link to this post

    Hello Rajiv Prashant,

    The error comes from this line:

    1.byte[] imageData = new byte[e.File.InputStream.Length];

    Please use

    1.byte[] imageData = new byte[e.File.ContentLength];

    instead. The error should vanish.

    Regards,
    Genady Sergeev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Cesar
    Cesar avatar
    5 posts
    Member since:
    Dec 2011

    Posted 30 May 2012 Link to this post

    Hello there, i have the same issue, my code reads the content length like u said but still gives me this error, please help:

    codebehind:


        protected static byte[] _UploadedImage;
        public static RadAjaxManager _RadAjaxManager;
        public static RadAjaxPanel _RadAjaxMainPanel;

     protected void Page_Load(object sender, EventArgs e)
        {
                _RadAjaxManager = (RadAjaxManager)Master.FindControl("RadAjaxManager1");
                _RadAjaxMainPanel = (RadAjaxPanel)Master.FindControl("AjaxMainPanel");
                RadAjaxLoadingPanel _RadAjaxLoadingPanel = (RadAjaxLoadingPanel)Master.FindControl("LoadingPanel1");
                _RadAjaxManager.AjaxSettings.Clear();
                _RadAjaxManager.AjaxSettings.AddAjaxSetting(rauImage, rbiUserPicture);
    }

      protected void rauImage_FileUploaded(object sender, Telerik.Web.UI.FileUploadedEventArgs e)
        {
            _UploadedImage = new byte[e.File.ContentLength];
            e.File.InputStream.Read(_UploadedImage, 0, e.File.ContentLength);
            rbiUserPicture.DataValue = _UploadedImage;
            e.File.InputStream.Dispose();
        }

    page:
    <%@ MasterType VirtualPath="~/User/UserDefault.master" %>
    ...
    ...
    <telerik:RadBinaryImage ID="rbiUserPicture" runat="server" Height="210px"
                                     ResizeMode="Crop" Width="180px" />
                                <telerik:RadAsyncUpload ID="rauImage" runat="server"
                                    onfileuploaded="rauImage_FileUploaded" RegisterWithScriptManager="true"
                                    Width="180px" AllowedFileExtensions="jpeg,jpg,gif,png" InputSize="10"
                                    MaxFileSize="5500000" TargetFolder="~/Temp/Photos"
                                    UploadedFilesRendering="BelowFileInput"  AutoAddFileInputs="False"
                                    OnClientValidationFailed="validationFailed" OnClientFileUploaded="fileUploaded"
                                    MaxFileInputsCount="1">
                                    <Localization Select="Update Picture" />
                                </telerik:RadAsyncUpload>


  5. Cesar
    Cesar avatar
    5 posts
    Member since:
    Dec 2011

    Posted 30 May 2012 Link to this post

    please help!
  6. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 04 Jun 2012 Link to this post

    Hi Cesar,

    Why do you call dispose on the input stream? This might cause unexpected behavior. Please comment out that line and let us know how it is going. If the issue persist please open a support ticket and attach there sample page and we will troubleshoot it.

    Greetings,
    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017