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

RadUpload GetAssociatedData Bug

1 Answer 54 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Alexey
Top achievements
Rank 2
Alexey asked on 23 Sep 2009, 07:40 AM
Hi,

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()
{
base.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);
fs.Close();

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

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

string associatedDataString = GetAssociatedDataString(addedFileId);

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

File.Delete(fullFileName);
}
}

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.

Thanks,
Alexey Zakharov.

1 Answer, 1 is accepted

Sort by
0
Ivan
Telerik team
answered on 24 Sep 2009, 01:58 PM
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,
Ivan
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.
Tags
Upload
Asked by
Alexey
Top achievements
Rank 2
Answers by
Ivan
Telerik team
Share this question
or