We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How do I get the uploaded filename on the server after a successfull uplaoid

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


4 Replies

DF David Farmer July 27, 2015 10:21 AM UTC

Got this working;

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



ES Ezhil S Syncfusion Team July 29, 2015 05:23 AM UTC

Hi David,

Thanks for sharing your code.
We are glad that your issue have been resolved.

Get back to us if you have further queries.

Regards,
Ezhil S


KN knjayGmail January 4, 2018 08:05 AM UTC

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 ? 



PO Prince Oliver Syncfusion Team January 5, 2018 11:00 AM UTC

Hi KnjayGmail, 

Thank you for contacting Syncfusion forums. 

We can send the newly generated file name and its path as JSON object via the response text that is returned from the handler. Refer to the following code. 

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; } 
 
} 

We can access the response text in the Uploadbox’s success event. Kindly refer to the following code. 

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

We have prepared a sample as per your requirement, please find the sample from the following location:  http://www.syncfusion.com/downloads/support/forum/119710/ze/UBmodifiedName-1902696265 

Regards, 
Prince 



Loader.
Live Chat Icon For mobile
Up arrow icon