开发者

SharePoint 2010: how to upload a file to a doc lib using javascript

I see this article e开发者_StackOverflow中文版xplaining 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>


UploadCtl solves this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜