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.
Unfortunately, activation email could not send to your email. Please try again.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

119710 Jul 23,2015 10:54 AM Jan 5,2018 06:00 AM ASP.NET Web Forms 4
loading
Tags: Uploadbox
David Farmer
Asked On July 23, 2015 10:54 AM

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


David Farmer
Replied On July 27, 2015 06:21 AM

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


Ezhil S [Syncfusion]
Replied On July 29, 2015 01:23 AM

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

knjayGmail
Replied On January 4, 2018 03:05 AM

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 ? 


Prince Oliver [Syncfusion]
Replied On January 5, 2018 06:00 AM

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 



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;