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

Is there any way to prepopulate the filelist

15 Answers 225 Views
Upload
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Evan Stineman
Top achievements
Rank 1
Evan Stineman asked on 20 Jun 2011, 01:12 PM
in the file uploader control?

thanks,
John Lee

15 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 20 Jun 2011, 01:28 PM
Hi Evan,

This is not possible due to (reasonable) browser security restrictions.

Regards,
Dimo
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Evan Stineman
Top achievements
Rank 1
answered on 20 Jun 2011, 02:16 PM
Not sure why this would be a security issue.

For example, my application includes a form that as the upload component.

1.  User fills out the form and uploads the required files.
2.  This information is saved to the database.
3.  User leaves the form.

4.  User returns to the form.
5.  Upload components pre-populates the file list with the files he previously uploaded (async mode, so files are already on the server)
6.  User can upload additional files or remove the existing ones.

I noticed the upload control simply has an <ul> wrapper to the file list.  I'm assuming there's some client-side methods that I can tap into to populate this list.

Is there a way to do this?

Thanks,
0
Dimo
Telerik team
answered on 20 Jun 2011, 03:33 PM
Hello Evan,

Sorry, I did not understand your question.

Listing previously uploaded files is possible, however the Upload component does not have native functionality of this kind. You will have to take care of storing the filenames (for example in the session) and display them by using DOM operations to populate the Upload's <ul> element. The same applies for deleting uploaded files - for example you can add buttons inside the <ul> that initiate a POST or GET request.

Kind regards,
Dimo
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Evan Stineman
Top achievements
Rank 1
answered on 21 Jun 2011, 02:17 PM
Thanks.  I ended up creating my own interface for that.
0
Vincent Girard
Top achievements
Rank 1
answered on 26 Jul 2011, 09:47 PM
Hi Evan,

I'm looking for a way to do this too, do you have some code somewhere that you could share with me?

Thanks!
0
Mattias
Top achievements
Rank 1
answered on 19 Sep 2011, 06:04 PM
Hi,
I also need this!
Can anyone share some code on how to prepopulate the list?

/Mattias
0
Mattias
Top achievements
Rank 1
answered on 19 Sep 2011, 08:20 PM
I know, very ugly... but it almost works.
The problem now is that nothing happens when clicking on Remove button.
I guess some event handling needs to be appended?

$(document).ready(function () {
        $(window).ready(function () {
            SetImageList();
        });
});
 
function SetImageList() {
        var wrapper = $(".t-upload");
        var ul = "<ul class='t-upload-files t-reset'>";
 
        @foreach(var file in Model.Files) {
             <text>ul += "<li class='t-file'><span class='t-icon t-success'>uploaded</span><span class='t-filename'>@file</span><button class='t-button t-button-icontext t-upload-action' type='button'><span class='t-icon t-delete'></span>Remove</button></li>";</text>
        }
        ul += "</ul>";
 
        wrapper.append(ul);
    }
0
cp
Top achievements
Rank 1
answered on 30 Dec 2011, 11:05 PM
Has anyone been able to get the Remove button to work with the script below?

Thanks,
0
cp
Top achievements
Rank 1
answered on 03 Jan 2012, 10:33 PM
Nevermind I got it working, all you have to do is attach the fileNames array to every DOM element.
0
Danny
Top achievements
Rank 1
answered on 13 Jan 2012, 06:34 AM
CP, I am having the same issue that the remove is not triggering any event.  Actually, I have a onRemove(e), but I'm getting jquery
Unable to get value of the property 'length'.

It seems like after I pre-populate the list of uploaded files, it doesn't know which file I'm trying to remove during the onclick.

Any assistance will be great.
0
cp
Top achievements
Rank 1
answered on 13 Jan 2012, 06:41 PM

Here is my approach to getting this to work (pretty much the code Mattias posted, I just more or less added the bottom line):

// Loop through all the files.
for (var i = 0; i < script.Files.length; i++) {
    // Build the li for every file.
    var li = "<li class=\"t-file\">";
    li += "<Build the li here>"
    li += "</li>";
    // Add it to the DOM.
    wrapper.append(li);
    // Add the data required by the Telerik control to the DOM.
    $(".t-file", ".t-upload").last().data("fileNames",  { files: new Array(script.Files[i]) });            
}

where script.Files is a collection of objects that among other things has a "Name" property.

The only problem I'm having is that I'm using an older version of the upload control, and attaching metadata seems to be broken for the delete part (I belive I read somewhere that this was fixed in the latest version).

Hope this helps.

0
Danny
Top achievements
Rank 1
answered on 14 Jan 2012, 02:55 AM
Thanks CP, I am going to try that out instead of the dirty way I am having mine function right now.
0
M
Top achievements
Rank 1
answered on 19 Apr 2012, 03:46 PM
Hi Danny and CP,
I read your replies and tried implementing the same but I am still not able to make the "Remove" link work. I think I am making some mistake in attaching the data() to the button, I dont know how the array should look and should be built. Can you please share the code.

Thanks.
0
Rob Carroll
Top achievements
Rank 2
answered on 17 Apr 2013, 08:29 PM
This questions has come up time and time again and is a common task that needs to be accomplished with any major web application.

Does Telerik have any plans to build this functionality in future releases?

This seems like a major roadblock.
0
Dimo
Telerik team
answered on 18 Apr 2013, 07:45 AM
Hi Rob,

We will consider implementing the discussed functionality if it gains enough popularity. Please vote here:

http://feedback.kendoui.com/forums/127393-kendo-ui-feedback/suggestions/2351571-prepopulate-upload-field-file-list

P.S. The above link refers to the Kendo UI Upload widget, as the MVC extensions' new development has been halted since mid 2012 and they will be discontinued after the Q2 2013 release.

Regards,

Dimo
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
Tags
Upload
Asked by
Evan Stineman
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Evan Stineman
Top achievements
Rank 1
Vincent Girard
Top achievements
Rank 1
Mattias
Top achievements
Rank 1
cp
Top achievements
Rank 1
Danny
Top achievements
Rank 1
M
Top achievements
Rank 1
Rob Carroll
Top achievements
Rank 2
Share this question
or