将文件上载到SharePoint文档库 [英] Uploading file to SharePoint Document Library

查看:80
本文介绍了将文件上载到SharePoint文档库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我们尝试了以下方法,使用ajax调用将文件上传到SharePoint文档库。


但是,文件不会在以下四种方法中上传。


方法-1:


var form = this.up('form')。getForm();


var filefield = Ext.getCmp('fileupload');


var file = filefield.getEl()。down('input [type = file]')。dom.files [0];


var reader = new FileReader();


var arrayBuffer = reader.readAsArrayBuffer(file);              


$ .ajax(com.ajaxOptions({


         ;        type:'POST',      


                 url:'https://xxx.qa.sbx.com/sites/1232456/DFX/Forms /AllItems.aspx',

               data:arrayBuffer ,


                cache:false,


                contentType:" application / vnd.ms-excel.12" ;,


                processData:true


}))。done(function(data){


alert('Successful ..');});}


我尝试使用不同的内容类型,如"application / vnd.ms-excel.12","application / vnd.openxmlformats-officedocument.spreadsheetml.sheet","application / x-www-form-urlencoded; charset = UTF-8"," application / octet-stream"
和"multipart / form-data"。在所有情况下,都不会使用ajax将文件上载到SharePoint文档库。


方法-2:


var form = this.up('form')。getForm();


var filefield = Ext.getCmp('fileupload');


var file = filefield.getEl()。down('input [type = file]')。dom.files [0];   


$ .ajax(com.ajaxOptions({


         ;        type:'POST',      


                 url:'https://xxx.qa.sbx.com/sites/1232456/DFX/Forms /AllItems.aspx',


                data:file ,


                cache:false,


                contentType:" application / vnd.ms-excel.12" ;,


                processData:true


}))。done(function(data){


alert('Successful ..');});}


我有tr使用不同的内容类型,例如"application / vnd.ms-excel.12","application / vnd.openxmlformats-officedocument.spreadsheetml.sheet","application / x-www-form-urlencoded; charset = UTF-8"," application / octet-stream"
和"multipart / form-data"。在所有情况下,都不会使用ajax将文件上载到SharePoint文档库。


方法-3:


var form = this.up('form')。getForm();


var filefield = Ext.getCmp('fileupload');


var file = filefield.getEl()。down('input [type = file]')。dom.files [0];


var xmlHttpRequest = new XMLHttpRequest();


var fileName ='Test.xlsx';


var target ='https://xxxx.qa.sbx.com/sites/127375/DFX/ Forms / AllItems.aspx';


var mimeType ='application / vnd.ms-excel.12';


xmlHttpRequest.open('POST ',target,true);


xmlHttpRequest.setRequestHeader('Content-Type',mimeType);


xmlHttpRequest.setRequestHeader('Content-Disposition ','attachment; filename ="'+ fileName +'"');


xmlHttpRequest.send(file);


我有尝试使用不同的内容类型,如"application / vnd.ms-excel.12","applicatio n / vnd.openxmlformats-officedocument.spreadsheetml.sheet","application / x-www-form-urlencoded; charset = UTF-8"," application / octet-stream"
和"multipart / form-data"。在所有情况下,都不会使用ajax将文件上载到SharePoint文档库。


Approach-4:使用REST API。


https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/upload-a-file-by-using-the-rest-api-and-jquery


在这种方法中,我找不到404问题。看起来REST API在SharePoint 2010中不支持。


请您告诉我们将文件上载到SharePoint文档库的方法。


如果我在这里丢失任何东西,请告诉我。


问候,


Sudheer










谢谢和问候,Sudheer

解决方案

https:// social.msdn.microsoft.com/Forums/en-US/650f6342-fd6a-4de8-b64a-a5736a4b31df/javascript-to-upload-a-file-to-sharepoint-2010-document-library

Hi,

We have tried following approaches to upload the file to SharePoint document library using ajax call.

But, file is not uploading in all below four approaches.

Approach-1:

var form = this.up('form').getForm();

var filefield = Ext.getCmp('fileupload');

var file = filefield.getEl().down('input[type=file]').dom.files[0];

var reader = new FileReader();

var arrayBuffer = reader.readAsArrayBuffer(file);             

$.ajax(com.ajaxOptions({

                type:'POST',      

                url: 'https://xxx.qa.sbx.com/sites/1232456/DFX/Forms/AllItems.aspx',

                data: arrayBuffer,

                cache: false,

                contentType: "application/vnd.ms-excel.12",

                processData: true

})).done(function (data) {

alert('Successful..');});}

I have tried with different content types like "application/vnd.ms-excel.12", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/x-www-form-urlencoded; charset=UTF-8", "application/octet-stream" and "multipart/form-data". In all the cases, file is not getting uploaded using ajax to SharePoint document library.

Approach-2:

var form = this.up('form').getForm();

var filefield = Ext.getCmp('fileupload');

var file = filefield.getEl().down('input[type=file]').dom.files[0];   

$.ajax(com.ajaxOptions({

                type:'POST',      

                url: 'https://xxx.qa.sbx.com/sites/1232456/DFX/Forms/AllItems.aspx',

                data: file,

                cache: false,

                contentType: "application/vnd.ms-excel.12",

                processData: true

})).done(function (data) {

alert('Successful..');});}

I have tried with different content types like "application/vnd.ms-excel.12", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/x-www-form-urlencoded; charset=UTF-8", "application/octet-stream" and "multipart/form-data". In all the cases, file is not getting uploaded using ajax to SharePoint document library.

Approach-3:

var form = this.up('form').getForm();

var filefield = Ext.getCmp('fileupload');

var file = filefield.getEl().down('input[type=file]').dom.files[0];

var xmlHttpRequest = new XMLHttpRequest();

var fileName = 'Test.xlsx';

var target = 'https://xxxx.qa.sbx.com/sites/127375/DFX/Forms/AllItems.aspx';

var mimeType = 'application/vnd.ms-excel.12';

xmlHttpRequest.open('POST', target, true);

xmlHttpRequest.setRequestHeader('Content-Type', mimeType);

xmlHttpRequest.setRequestHeader('Content-Disposition', 'attachment; filename="' + fileName + '"');

xmlHttpRequest.send(file);

I have tried with different content types like "application/vnd.ms-excel.12", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/x-www-form-urlencoded; charset=UTF-8", "application/octet-stream" and "multipart/form-data". In all the cases, file is not getting uploaded using ajax to SharePoint document library.

Approach-4: Using REST API.

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/upload-a-file-by-using-the-rest-api-and-jquery.

In this approach, I am getting 404 not found issue. It looks like REST APIs are not supporting in SharePoint 2010.

Request you to please let us know the approach to upload the file to SharePoint document library.

Please let me know if I am missing anything here.

Regards,

Sudheer




Thanks & Regards, Sudheer

解决方案

https://social.msdn.microsoft.com/Forums/en-US/650f6342-fd6a-4de8-b64a-a5736a4b31df/javascript-to-upload-a-file-to-sharepoint-2010-document-library


这篇关于将文件上载到SharePoint文档库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆