sharepoint REST API 獲取文件夾及文件

使用REST操做文件夾:web

 獲取文件夾json

1 url: http://site url/_api/web/GetFolderByServerRelativeUrl('/Shared Documents')/folders 
2 method: GET 3 headers:  
4     Authorization: "Bearer " + accessToken 5     accept: "application/json;odata=verbose" or "application/atom+xml"

建立文件夾api

1 url: http://site url/_api/web/folders 
2 method: POST 3 body: { '__metadata': { 'type': 'SP.Folder' }, 'ServerRelativeUrl': '/document library relative url/folder name'} 4 Headers:   
5     Authorization: "Bearer " + accessToken 6     X-RequestDigest: form digest value 7     accept: "application/json;odata=verbose"  
8     content-type: "application/json;odata=verbose"  
9     content-length:length of post body

更新文件夾app

 1 url: http://site url/_api/web/GetFolderByServerRelativeUrl('/Folder Name') 
 2 method: POST  3 body: { '__metadata': { 'type': 'SP.Folder' }, 'Name': 'New name' }  4 Headers:   
 5      Authorization: "Bearer " + accessToken  6     X-RequestDigest: form digest value  7     "IF-MATCH": etag or "*"  
 8     "X-HTTP-Method":"MERGE",  
 9     accept: "application/json;odata=verbose"  
10     content-type: "application/json;odata=verbose"  
11     content-length:length of post body

刪除文件夾post

1 url: http://site url/_api/web/GetFolderByServerRelativeUrl('/Folder Name') 
2 method: POST 3 Headers:   
4      Authorization: "Bearer " + accessToken 5      X-RequestDigest: form digest value 6     "IF-MATCH": etag or "*"  
7     "X-HTTP-Method":"DELETE"

使用REST操做文件:atom

獲取某文件夾下的所有文件url

1 url: http://site url/_api/web/GetFolderByServerRelativeUrl('/Folder Name')/Files 
2 method: GET 3 headers:  
4     Authorization: "Bearer " + accessToken 5     accept: "application/json;odata=verbose" or "application/atom+xml"

獲取指定文件名的文件內容spa

1 url: http://site url/_api/web/GetFolderByServerRelativeUrl('/Folder Name')/Files('file name')/$value 
2 method: GET 3 headers:  
4     Authorization: "Bearer " + accessToken

或經過URL獲取文件code

1 url: http://site url/_api/web/GetFileByServerRelativeUrl('/Folder Name/file name')/$value 
2 method: GET 3 headers:  
4     Authorization: "Bearer " + accessToken

示例:將某文件添加到指定文件夾下orm

1 url: http://site url/_api/web/GetFolderByServerRelativeUrl('/Folder Name')/Files/add(url='a.txt',overwrite=true) 
2 method: POST 3 body: "Contents of file"  
4 Headers:   
5     Authorization: "Bearer " + accessToken 6     X-RequestDigest: form digest value 7     content-length:length of post body

使用PUT更新一個文件

1 url: http://site url/_api/web/GetFileByServerRelativeUrl('/Folder Name/file name')/$value 
2 method: PUT 3 body: "Contents of file."  
4 Headers:   
5     Authorization: "Bearer " + accessToken 6     X-RequestDigest: form digest value 7     X-HTTP-Method:"PUT"  
8     content-length:length of post body

文件簽出

1 url: http://site url/_api/web/GetFileByServerRelativeUrl('/Folder Name/file name')/CheckOut(), 
2 method: POST 3 headers:  
4     Authorization: "Bearer " + accessToken 5     X-RequestDigest: form digest value

文件簽入

1 url: http://site url/_api/web/GetFileByServerRelativeUrl('/Folder Name/file name')/CheckIn(comment='Comment',checkintype=0) 
2 method: POST 3 headers:  
4     Authorization: "Bearer " + accessToken 5     X-RequestDigest: form digest value

刪除文件

1 url: http://site url/_api/web/GetFileByServerRelativeUrl('/Folder Name/file name') 
2 method: POST 3 headers:  
4     Authorization: "Bearer " + accessToken 5      X-RequestDigest: form digest value 6     IF-MATCH: etag or "*"  
7     X-HTTP-Method:"DELETE"

操做大文件(2G)

1 url: http://site url/_api/web/GetFolderByServerRelativeUrl('/Folder Name')/Files/Add(url='file name', overwrite=true) 
2 method: POST 3 body: contents of binary file  
4 headers:  
5     Authorization: "Bearer " + accessToken 6     X-RequestDigest: form digest value 7     content-type: "application/json;odata=verbose"  
8     content-length:length of post body

經過REST操做列表項的附件

獲取全部的附件文件

1 url: http://site url/_api/web/lists/getbytitle('list title')/items(item id)/AttachmentFiles/ 
2 method: GET 3 headers:  
4     Authorization: "Bearer " + accessToken 5     accept: "application/json;odata=verbose" or "application/atom+xml"

指定附件名獲取

1 url: http://site url/_api/web/lists/getbytitle('list title')/items(item id)/AttachmentFiles('file name')/$value 
2 method: GET 3 headers:  
4     Authorization: "Bearer " + accessToken 5     accept: "application/json;odata=verbose" or "application/atom+xml"

添加附件

1 url: http://site url/_api/web/lists/getbytitle('list title')/items(item id)/AttachmentFiles/ add(FileName='file name') 
2 method: POST 3 headers:  
4     Authorization: "Bearer " + accessToken 5     body: "Contents of file."  
6     X-RequestDigest: form digest value 7     content-length:length of post body

更新附件

1 url: http://site url/_api/web/lists/getbytitle('list title')/items(item id)/AttachmentFiles('file name')/$value 
2 method: POST 3 body: "Contents of file."  
4 headers:  
5     Authorization: "Bearer " + accessToken 6     "X-HTTP-Method":"PUT"  
7     X-RequestDigest: form digest value 8     content-length:length of post body
相關文章
相關標籤/搜索