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

Get folder path from dropdownlist

3 Answers 116 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Mattias
Top achievements
Rank 1
Mattias asked on 05 Mar 2009, 02:15 PM
Hi,
I need to set the path of where the file is saved from a dropdownlist but I can't figure out where to set it.
<table> 
        <tr> 
            <td>Spara i mapp:</td> 
            <td><asp:DropDownList ID="dropDownListUploadFolder" runat="server"></asp:DropDownList></td
        </tr> 
        <tr> 
            <td>Hämta fil:</td> 
            <td><telerik:RadUpload ID="RadUpload1" runat="server" ControlObjectsVisibility="None" Width="300px" Localization-Select="Hämta" Skin="Vista"></telerik:RadUpload> </td> 
        </tr> 
        <tr> 
            <td></td
            <td><asp:Button ID="Button1" runat="server" Text="Ladda upp" OnClick="Button1_Click" /></td
        </tr> 
    </table> 

I have tried to set the RadUpload.TargetFolder in the Button1_Click event and also on Page_Load but it still not saves it there!

Help please! :)

3 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 06 Mar 2009, 11:36 AM
Hello Mattias,

This functionality can be achieved using .SaveAs() method of the UploadedFile class. For more information how to deal with the uploaded files please refer to this help article. For your convenience I have attached sample project reproducing the desired scenario.

I hope this information helps.

Greetings,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Mattias
Top achievements
Rank 1
answered on 08 Mar 2009, 03:57 PM
Hi Genady,
I don't see any attached project?! But that's ok! :)
This code works but I'm not sure if it is the "best practice way".
I think the upload is pretty slow, is there any overhead in this?
protected void Button1_Click(object sender, System.EventArgs e) 
        { 
            UploadedFile file = RadUpload1.UploadedFiles[0];// UploadedFile.FromHttpPostedFile(Request.Files[inputFile.UniqueID]); 
 
            if (!Object.Equals(file, null)) 
            { 
                file.SaveAs(Server.MapPath(dropDownListUploadFolder.SelectedValue) + "\\" + file.GetName()); 
                LooongMethodWhichUpdatesTheProgressContext(file); 
 
                Response.Redirect(Request.Path + "?MenuID=" + Request.QueryString["MenuID"]); 
            } 
        } 
 
        private void LooongMethodWhichUpdatesTheProgressContext(UploadedFile file) 
        { 
            const int total = 100; 
 
            RadProgressContext progress = RadProgressContext.Current; 
             
            for (int i = 0; i < total; i++) 
            { 
                progress.PrimaryTotal = 1; 
                progress.PrimaryValue = 1; 
                progress.PrimaryPercent = 100; 
 
                progress.SecondaryTotal = total; 
                progress.SecondaryValue = i; 
                progress.SecondaryPercent = i; 
 
                progress.CurrentOperationText = file.GetName() + " is being processed..."
 
                if (!Response.IsClientConnected) 
                { 
                    //Cancel button was clicked or the browser was closed, so stop processing 
                    break
                } 
 
                //Stall the current thread for 0.1 seconds 
                System.Threading.Thread.Sleep(100); 
            } 
        }     

0
Genady Sergeev
Telerik team
answered on 09 Mar 2009, 10:02 AM
Hi Mattias,

Something must have gone wrong with the attachment, please excuse me, I am attaching it once again.

In concern to your posted code - keep in mind that when Button1_Click event fires, the files are already uploaded! In general, all server events fire when the files are already uploaded, so this cannot add overhead to the upload itself. In addition custom progress monitoring ( as it is your code ) is necessary only when you want to use the progress monitor for a task different than uploading files. You see, the progress area is automatically following the file upload progress, there is no need to write any source code at all!

I hope this information helps.

Regards,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Upload (Obsolete)
Asked by
Mattias
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Mattias
Top achievements
Rank 1
Share this question
or