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.
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.
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.