This question is locked. New answers and comments are not allowed.
I am using the RadUpload in a SharePoint 2010 page to set property values and upload documents to a document library.
The question I have is: If an error occurs within the try/catch block of ProcessStream(), the error shown in the Silverlight client is "Handler not found or execution of the handler failed". How should an error be handled that occurs during the ProcessStream()? (I've tried adding this.AddReturnFileParam as well as this.AddReturnParam, but on the FileUploadFailed event, the e.HandlerData.CustomData is empty.)
A related question: If you choose to try to upload a new file in the RadUpload control after a failure in the ProcessStream(), it will appear to start uploading, but never upload the file. The FileUploadFailed event files, but the UploadFinished never fires - so it appears as through the previous process is hanging and not allowing subsequent uploads. How do I terminate the previous process to allow a new attempt after a failed upload?
I've posted reduced code below.
The question I have is: If an error occurs within the try/catch block of ProcessStream(), the error shown in the Silverlight client is "Handler not found or execution of the handler failed". How should an error be handled that occurs during the ProcessStream()? (I've tried adding this.AddReturnFileParam as well as this.AddReturnParam, but on the FileUploadFailed event, the e.HandlerData.CustomData is empty.)
A related question: If you choose to try to upload a new file in the RadUpload control after a failure in the ProcessStream(), it will appear to start uploading, but never upload the file. The FileUploadFailed event files, but the UploadFinished never fires - so it appears as through the previous process is hanging and not allowing subsequent uploads. How do I terminate the previous process to allow a new attempt after a failed upload?
I've posted reduced code below.
public override bool SaveChunkData(string filePath, long position, byte[] buffer, int contentLength, out int savedBytes)
{
try
{
requestUrl = this.GetQueryParameter("requestUrl");
docLibName = this.GetQueryParameter("docLibName");
currentFolderName = this.GetQueryParameter("currentFolderName");
//get dynamic property list
propertyList = this.GetQueryParameter("propertyList");
bool result;
this.PrepareAccountSession();
if (!this.PrepareStorageFolder())
{
result = false;
}
string FilePath = this.GetFilePath();
result = base.SaveChunkData(FilePath, position, buffer, contentLength, out savedBytes);
return result;
}
catch (Exception ex)
{
this.AddReturnParam(RadUploadConstants.ParamNameMessage, ex.Message);
this.AddReturnFileParam(RadUploadConstants.ParamNameMessage, ex.Message);
string fileName = this.GetQueryParameter(RadUploadConstants.ParamNameFileName);
this.AddReturnFileParam(RadUploadConstants.ParamNameSuccess, false);
this.AddReturnFileParam(RadUploadConstants.ParamNameFileName, fileName);
this.AddReturnFileParam(RadUploadConstants.ParamNameFinalFileRequest, true);
savedBytes = 0;
return false;
}
}
public override void ProcessStream()
{
try
{
base.ProcessStream();
for (int i = 0; i < Request.Files.Count; i++)
{
HttpPostedFile file = Request.Files[i];
string fileName = this.Request.Form[i.ToString() + "_RadUAG_fileName"]; // GetFileName();
string fullPath = this.GetTargetFolder();
string filename = fullPath + "\\" + fileName;
if (file.ContentLength != 0)
{
file.SaveAs(filename);
FileStream stream = new FileStream(filename, FileMode.Open);
SPSite site = new SPSite(requestUrl);
using (SPSite elevatedSite = new SPSite(requestUrl))
{
using (SPWeb web = elevatedSite.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPFile newFile;
//using the below method for any property types such as multichoice will throw the error:
//"Only String, INT, and DateTime datatypes can be used as the value in Properties."
//at Microsoft.SharePoint.Utilities.SPUtility.UpdateArrayFromHashtable(Object& o, Hashtable ht)
//Hashtable hashtable = new Hashtable();
//hashtable.Add(propKey, propValue);
//Hashtable properties = hashtable;
if (currentFolderName == "/")
{
//use root folder
SPDocumentLibrary library = (SPDocumentLibrary)web.Lists[docLibName];
SPFolder rootFolder = library.RootFolder;
//use this method if using hashtable for properties
//SPFile newFile = rootFolder.Files.Add(string.Format("{0}/{1}", rootFolder.Url, fileName), stream, properties, true);
//use this method if altering the list item after upload
newFile = rootFolder.Files.Add(string.Format("{0}/{1}", rootFolder.Url, fileName), stream, true);
}
else
{
SPFolder currentSPFolder = web.GetFolder(currentFolderName);
newFile = currentSPFolder.Files.Add(string.Format("{0}/{1}", currentSPFolder.Url, fileName), stream, true);
}
//set item properties
if (newFile.Item != null)
{
SPListItem listItem = newFile.Item;
//assign column values here
//throw error when column does not exist
listItem["SomeBadColumn"] = "FOO";
listItem.Update();
newFile.Update();
}
stream.Close();
}
}
}
} //for
}
catch (Exception ex)
{
this.AddReturnParam(RadUploadConstants.ParamNameMessage, ex.Message);
this.AddReturnFileParam(RadUploadConstants.ParamNameMessage, ex.Message);
string fileName = this.Request.Form[RadUploadConstants.ParamNameFileName];
string filePath = this.GetTargetFolder();
this.AddReturnFileParam(RadUploadConstants.ParamNameSuccess, false);
this.AddReturnFileParam(RadUploadConstants.ParamNameTargetFolder, filePath);
this.AddReturnFileParam(RadUploadConstants.ParamNameFileName, fileName);
this.AddReturnFileParam(RadUploadConstants.ParamNameTargetPhysicalFolder, filePath);
this.AddReturnFileParam(RadUploadConstants.ParamNameFinalFileRequest, true);
return;
}
}