RadUpload GetAssociatedData Bug

2 posts, 0 answers
  1. Alexey
    Alexey avatar
    79 posts
    Member since:
    Oct 2008

    Posted 23 Sep 2009 Link to this post


    In our system we use database to store files. When new file is added we need to send its generated database id back to client.

            public override void ProcessStream()

    if (this.IsFinalFileRequest())
    string fileName = this.Request.Form[RadUploadConstants.ParamNameFileName];
    string fullFileName = Path.Combine(Path.Combine(this.Request.PhysicalApplicationPath, @"TempFolder\"), fileName);

    var fs = new FileStream(fullFileName, FileMode.Open);
    var fileAsBytes = new byte[fs.Length];
    fs.Read(fileAsBytes, 0, fileAsBytes.Length);

    long? directoryId = this.Request.Form["SelectedDirectory"] == null ? (long?)null : Convert.ToInt64(this.Request.Form["SelectedDirectory"]);

    long addedFileId = this.fileSystemRepository.AddFile(
    Path.HasExtension(fullFileName) ? Path.GetExtension(fullFileName).Substring(1) : string.Empty,

    string associatedDataString = GetAssociatedDataString(addedFileId);

    this.AddReturnParam(RadUploadConstants.ParamNameAssociatedData, associatedDataString);
    this.AddReturnParam(RadUploadConstants.ParamNameSuccess, true);


    private static string GetAssociatedDataString(long addedFileId)
    string associatedDataString = string.Empty;

    var associatedData = new Dictionary<string, object> { { "Id", addedFileId } };
    if (associatedData.Count > 0)

    foreach (string key in associatedData.Keys)
    object value = associatedData[key];
    if (value == null)
    value = "null";
    value = "\"" + value.ToString().Replace(@"\", @"\\") + "\"";
    associatedDataString = associatedDataString + "{" + string.Format("\"Key\":\"{0}\",\"Value\":{1}", key, value) + "},";
    associatedDataString = associatedDataString.TrimEnd(new[] { ',' });
    return associatedDataString;

    We tried to use GetAssociatedData overloading for this purpose but failed, because it is serialized before in base.ProcessStream()

    Currently we hacked this, but manually serializing AssociatedDatat into AssociatedDataString, which we added via AddReturnParam.

    Alexey Zakharov.
  2. Ivan
    Ivan avatar
    519 posts

    Posted 24 Sep 2009 Link to this post

    Hello Alexey,

    Thank you for your strong interest in our upload control.

    In general you already accomplished the task. I can only suggest that you should rely on the ChunkTag mechanism in order to avoid intermediate saving into a file. I hope you will find many interesting information in our upload related articles.

    Best wishes,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top