Hi, I'm using your asp.net Uploadbox control with the associated handler files for Save and delete file. The upload process is working correctly but I'm having difficulty retrieving the uploaded file(s) name on the server after upload. The UploadBox_Complete event is firing but I can't get the file names.
thanks
Private Sub UploadBox_Complete(sender As Object, e As Syncfusion.JavaScript.Web.UploadBoxCompleteEventArgs) Handles UploadBox.Complete
Dim strName As String
Dim data As Dictionary(Of String, Object) = e.FileStatus
For Each keyval As KeyValuePair(Of String, Object) In data
If keyval.Key = "name" Then
strName = keyval.Value.ToString
End If
Next
End Sub
Hi,
In “.ashx” file I'm
changing the original file name to randomly generated file name. I want randomly generated saved file name and the path (path on server) in "UploadBox_Complete" event handler. Can you please help on this front ?
public class saveFiles : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
List<uploadFile> Uploadfiles = new List<uploadFile>();
string targetFolder = HttpContext.Current.Server.MapPath("uploadfiles");
if (!Directory.Exists(targetFolder))
{
Directory.CreateDirectory(targetFolder);
}
HttpRequest request = context.Request;
HttpFileCollection uploadedFiles = context.Request.Files;
if (uploadedFiles != null && uploadedFiles.Count > 0)
{
for (int i = 0; i < uploadedFiles.Count; i++)
{
string fileName = uploadedFiles[i].FileName;
Uploadfiles.Add(new uploadFile { oldname = fileName, newname = "Randomly Generated Name here", path = targetFolder });
int indx = fileName.LastIndexOf("\\");
if (indx > -1)
{
fileName = fileName.Substring(indx + 1);
}
uploadedFiles[i].SaveAs(targetFolder + "\\" + fileName);
}
}
else
{
}
var json = JsonConvert.SerializeObject(Uploadfiles);
context.Response.ContentType = "text/json";
context.Response.Write(json);
}
public bool IsReusable
{
get
{
return false;
}
}
}
public class uploadFile
{
public string oldname { get; set; }
public string newname { get; set; }
public string path { get; set; }
} |
<ej:UploadBox ID="Upload1" SaveUrl="saveFiles.ashx" RemoveUrl="removeFiles.ashx" runat="server" ClientSideOnSuccess="fileuploadSuccess" ></ej:UploadBox>
<script>
function fileuploadSuccess(e) {
var FileData = JSON.parse(e.responseText)[0];
alert("New Name: " + FileData.newname);
alert("Path: " + FileData.path);
}
</script> |