Custom AsyncUploadResult does not support File path or "\"

Thread is closed for posting
2 posts, 0 answers
  1. Chris
    Chris avatar
    58 posts
    Member since:
    Feb 2012

    Posted 21 Sep 2014 Link to this post

    Hi there,

    I have been using the Upload control for quite a while now using my own custom AsyncUploadResult class.
    What happens now is unexpected as I'm trying to save the absolute path to the uploaded file into a string variable and this ends up in a error thrown statint the escape sequence is not recognized. See below :

    My custom upload class :
    1.public class DataUploadResult : AsyncUploadResult
    2.    {
    3.        private string sourceFilePath;
    4.        public string SourceFilePath { get { return this.sourceFilePath; } set { this.sourceFilePath = value; } }
    5.    }

    My UploadHandler:
    1.protected override IAsyncUploadResult Process(UploadedFile file, HttpContext context, IAsyncUploadConfiguration configuration, string tempFileName)
    2.        {
    3.            DataUploadResult result = CreateDefaultUploadResult<DataUploadResult>(file);
    4.            result.SourceFilePath = string.Format(@"{0}\{1}", configuration.TempTargetFolder, tempFileName);
    5.        }
                return result;

    And my FileUploaded event Handler;
    1.protected void RauDataUpload_OnFileUploaded(object sender, FileUploadedEventArgs e)
    2.    {
    3.            DataUploadResult result = e.UploadResult as DataUploadResult;
    4.    }

    And it fails on row 3 with the following error message:
    "Exception has been thrown by the target of an invocation."
    Unrecognized escape sequence. (430): {"SourceFilePath":"C:\Dev\NRP\NRP\Study\UploadTemp\1411349019322101001_20140410-125730_PTAP.sld"}

    Is this a bug or am I doing something wrong ?

    Obviously I trimmed my code for my example here, the actual Custom Upload result embeds 19 variables and everything worked perfectly until I add this SourceFilePath string to it.

    Any clue ? Looks like '\' isn't supported.

    Cheers,

    Chris

  2. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 24 Sep 2014 Link to this post

    Hi Chris,

    The custom result will be returned back to the client in the OnFileUploaded event:

    <telerik:RadAsyncUpload
        runat="server"
        ID="RauDataUpload"
        HttpHandlerUrl="~/Handlers/Handler.ashx"
        OnClientFileUploaded="onClientFileUploaded"
        OnFileUploaded="RauDataUpload_FileUploaded">
    </telerik:RadAsyncUpload>
     
    <asp:Button Text="text" runat="server" />
     
    <script>
        function onClientFileUploaded(sender, args) {
            var result = args.get_fileInfo().SourceFilePath;
            alert(result);
        }
    </script>

    It is not possible to get it on the server from the arguments of the OnFileUploaded event. Actually you can save the file directly into the Process() method of  handler. There is no need to handle the OnFileUploaded event. For example:

    protected override IAsyncUploadResult Process(UploadedFile file, HttpContext context, IAsyncUploadConfiguration configuration, string tempFileName)
    {      
        DataUploadResult result = CreateDefaultUploadResult<DataUploadResult>(file);
     
        string targetFolder = context.Server.MapPath("~/Uploads/");
        string fileName = file.GetName();
        file.SaveAs(targetFolder + fileName);
     
        result.SourceFilePath = targetFolder + fileName;
     
        return result;
    }

    I hope this helps.

    Regards,
    Hristo Valyavicharski
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top