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

Problem using RadAsyncUpload

4 Answers 224 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Rajiv Prashant
Top achievements
Rank 1
Rajiv Prashant asked on 14 Sep 2010, 12:53 PM
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.



4 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 17 Sep 2010, 10:02 AM
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
0
Cesar
Top achievements
Rank 1
answered on 30 May 2012, 07:07 AM
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>


0
Cesar
Top achievements
Rank 1
answered on 30 May 2012, 07:07 AM
please help!
0
Genady Sergeev
Telerik team
answered on 04 Jun 2012, 11:28 AM
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.
Tags
Upload (Obsolete)
Asked by
Rajiv Prashant
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Cesar
Top achievements
Rank 1
Share this question
or