2

I see this article explaining how to upload a file using client API's from a fully trusted app.

How to implement such functionality but from javascript?

For example, I have this code in which I have both the local path of the file and the SharePoint doc lib, how do I complete it?

Thanks!

PS: I'm guessing there must be some fully trusted component involved in the client in order to achieve this, otherwise would be a javascript security hole, but which one would be the right one to use in this case against SharePoint?

    <script type="text/javascript">
        var list;
        var filePath;
        function ShowUploadDialog() {
            // get file path user chooses through a dialog
            var fileDialog = document.getElementById("fileDialog");
            fileDialog.click();
            filePath = fileDialog.value;

            // get list
            var context = new SP.ClientContext.get_current();
            var site = context.get_site();
            var web = site.get_rootWeb();
            this.collList = web.get_lists();
            list = collList.getByTitle("My doc library");
            context.load(list);
            context.executeQueryAsync(Succeeded, Failed);
        }
        function Succeeded(sender, args) {
            // I HAVE HERE THE list AND THE filePath, HOW CAN UPLOAD THE FILE TO THE LIST?
        }
        function Failed(sender, args) {
            alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
        }
    </script>
Community
  • 1
  • 1
Ariel
  • 5,752
  • 5
  • 49
  • 59
  • Have you tried looking at the docs for the Javascript client object model? http://msdn.microsoft.com/en-us/library/ee538253.aspx – Michael Dillon May 23 '11 at 17:40

1 Answers1

0

UploadCtl solves this.

Ariel
  • 5,752
  • 5
  • 49
  • 59