Kendo UI Upload does not seem to return onSuccess even though the file gets uploaded. Below is the code I am using in C# on page load. I need to file name to be returned
What am I doing wrong here?
public string ProcessRequest()
{
Response.Expires = -1;
try
{
HttpPostedFile postedFile = Request.Files["files"];
string savepath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["ExcelImport"]);
string filename = CL.GenerateUniqueName(postedFile.FileName, Session["LoginUserID"].ToString()); \\ <== generate a unique file name and return it to upload
if (!Directory.Exists(savepath))
Directory.CreateDirectory(savepath);
string strCompath = Path.Combine(savepath, filename);
postedFile.SaveAs(strCompath);
Response.ContentType = "text/plain";
string json = JsonConvert.SerializeObject(filename, Formatting.Indented); //<== tried to convert to json but still does not work
return "";
}
catch (Exception ex)
{
Response.Write(ex.ToString());
return ex.ToString();
}
}
Javascript of success code
function onSuccess(e) {
console.log("Success (" + e.operation + ") :: " + getFileInfo(e));
}
Edit 1
I found that entire html seems to be rendered after uploading. How do I just return the uniquefilename?
Update
What I did to resolve this issue was call another aspx file that had no html and got the correct response. Not sure if this is the correct way but works for me. Now just need to find out how to get the unique file name back.
My Code:
$("#files").kendoUpload({
async: {
saveUrl: "Response.aspx", //<== earlier this was pointing to the current aspx where the control is
removeUrl: "remove",
autoUpload: true
},
showFileList: true,
success: onSuccess,
remove: onRemove,
upload: onUpload,
complete: onComplete,
error: onerror
});
Server Code:
protected void Page_Load(object sender, EventArgs e)
{
Response.Expires = -1;
try
{
HttpPostedFile postedFile = Request.Files["files"];
string savepath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["ExcelImport"]);
string filename = CL.GenerateUniqueName(postedFile.FileName, Session["LoginUserID"].ToString());
if (!Directory.Exists(savepath))
Directory.CreateDirectory(savepath);
string strCompath = Path.Combine(savepath, filename);
postedFile.SaveAs(strCompath);
Context.Response.Clear();
Context.Response.ContentType = "text/plain";
Context.Response.Write("{}");
}
catch (Exception ex)
{
Response.Write(ex.ToString());
// return ex.ToString();
}
}