This is a migrated thread and some comments may be shown as answers.

AsyncUpload files format being changed

1 Answer 49 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Joshua
Top achievements
Rank 1
Joshua asked on 24 Feb 2016, 03:29 PM

Hello

I am using AsyncUpload to upload photos and store them in a folder that exists inside my project

        <asp:Label ID="PhotoLabel" runat="server" Text="Upload a photo"></asp:Label>
        <telerik:RadAsyncUpload RenderMode="Lightweight" runat="server" ManualUpload="false"  ID="AsyncUpload1" MultipleFileSelection="Disabled" OnFileUploaded="AsyncUpload1_FileUploaded"></telerik:RadAsyncUpload>
        <telerik:RadButton runat="server" Text="Sibmit new photos" OnClick="UploadFiles_Click"></telerik:RadButton>
        <asp:Label ID="error" runat="server" Text="" Visible="false"></asp:Label>

 

    protected void UploadFiles_Click(object sender, EventArgs e)
    {
        try
        {
            if(AsyncUpload1.UploadedFiles.Count > 0)
            {
                foreach (UploadedFile file in AsyncUpload1.UploadedFiles)
                {
                    string targetFolder = HttpContext.Current.Server.MapPath("~/images");
                    string targetPath = Path.Combine(targetFolder, file.ToString());

                    file.SaveAs(targetPath);    
                }
                error.Text = "File Uploaded";
                error.Visible = true;

            }
            else
            {
                error.Text = "no files to upload";
                error.Visible = true;
                return;
            }
        }
        catch(Exception ex)
        {
            error.Text = ex.ToString();
            error.Visible = true;
        }
    }

 

This code works. And stores a file on the correct folder. The problem is that instead of it being a png like I uploaded its a 'Telerik.Web.UI.AsyncUploadedFile'

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 29 Feb 2016, 11:47 AM
Hello Joshua,

In order to save the file and keep its name and extension you will have to change the following line in the UploadFiles_Click() handler:
string targetPath = Path.Combine(targetFolder, file.ToString());

to:
string targetPath = Path.Combine(targetFolder, file.FileName);

More information on how the files can be manipulated on the server side is available in the following article.

Regards,
Ivan Danchev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
AsyncUpload
Asked by
Joshua
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Share this question
or