Hiển thị các bài đăng có nhãn Sharepoint 2013. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Sharepoint 2013. Hiển thị tất cả bài đăng

Thứ Tư, 15 tháng 2, 2017

SharePoint .NET Server, CSOM, JSOM, and REST API index

Sharepoint API index
Sử dụng API index để tra cứu những đối tượng hay dùng nhất:

+ API: AttachmentCollection, SPAttachmentCollection
+ SP.Object/Enumeration (sp.js): SP.AttachmentCollection
+ REST Endpoint": …/_api/web/lists('<list id>')/items(<item id>)/attachmentfiles

+ BasePermissions SPBasePermissions
+ SP.BasePermissions object
+ N/A

+ CalendarType SPCalendarType
+ SP.CalendarType enumeration
+ N/A 
 

+ ChangeCollection SPChangeCollection
+ SP.ChangeCollection object
+ …/_api/web/getchanges(changequery)

Tham khảo chi tiết

SharePoint-Hosted App - Part 4

SharePoint-Hosted App

A SharePoint hosted app is one where the business logic is implemented within the client (browser). These types of apps do not have any external dependencies nor do they use any server-side code but they can utilize some SharePoint artifacts such as lists and libraries for storing content. SharePoint will host the app in a special isolated subweb (SPWeb) that has all the same capabilities of a regular SPWeb. All logic & code runs in the client. Apps could make external service calls from the client using some provided tools.

Understanding the App URL

Consider an app installed in the SPWeb http://intranet.mydomain.com .The app URL will be (for example): http://app-bf473b5225nn0f.apps.mydomain.com/SharePointAppWebTitle
AppUID and AppName are highlighted in bold in the above Url. App UID is a unique 14 character identifier that is given to each app installation in that particular customer /tenancy. This makes the domain unique for each app. App Name is the name of the SPWeb folder under which the app is installed. Currently this is a GUID and is automatically generated. In the case of a hosted deployment, the root domain (mydomain.com in the above scenario) is always SharePoint.com.

Explore App Solution Structure

Once you have set up your VM for SharePoint 2013, open Visual Studio 2012 and create a new project using template “Apps for SharePoint 2013” for creating apps for SharePoint.


Provide the name of the SharePoint app, the SharePoint which you will use for debugging and select the option where you would like to host SharePoint app. For this post, we will select “SharePoint-hosted” as shown in screenshot below:


The following screenshot shows a new project created from “Apps for SharePoint 2013” template in Project Explorer and illustrates its structure.


App Manifest
Any app for SharePoint (be it SharePoint hosted or cloud hosted) includes an appmanifest.xml file. The appmanifest.xml defines the high level app’s attributes like the title, internal name, icon path and version of the app. The most important item specified in the app manifest is the URL of the start page, which is the page that opens when the app is started.

If app needs to access any SharePoint resources outside the app web, then requests for permission is also defined in the app manifest via Permissions tab. You can also define a list of the prerequisites in app manifest, if any, that must be available to the app in order for the app to be installed. For example, certain features may need to be installed and activated, and certain services may need to be licensed and installed. You can right click on app manifest and select “view code” to view the details:

Notice that with start page, there is a dynamic token prefix as ~appWebUrl, and SharePoint will replace this dynamic token at runtime depending on which site the app is installed. App Principal is needed for identification, for authentication and authorization purposes, of the app. For SharePoint hosted app, App Principal will always be internal as SharePoint is going to track the identity of the app internally and does not need any outside help.
Default.aspx (i.e. Default Start Page)
Once you open the default start page of the SharePoint hosted app (i.e. default.aspx), you’ll find that Visual Studio automatically adds two content place holders  in it i.e. PlaceHolderAdditionalPageHead and PlaceHolderMain. Inside of PlaceHolderAdditionalPageHead, Visual Studio automatically adds the jQuery libraries and link to app.css and app.js. You can directly start adding styles for default.aspx in app.css and can add scripts in app.js.

A SharePoint hosted app can have many pages, it’s just the template provides you with the default start page. You can add as many pages or script files or CSS.  
Hello World SharePoint Hosted App
Without making any code modifications in above project, if you right click on the project, and select “deploy”, it will deploy the app to SharePoint site. You can also change the site URL to deploy the app to your O365 tenant site collection. You can go
to site content and clicking on the app “My First SharePoint App” will open up the default page of the app as shown below.
 
The hello world app “My First SharePoint App” deployed above displays the name of the logged in user. This name is fetched using the SharePoint 2013 Client Side Object Model (CSOM) via JavaScript. CSOM can be used using JavaScript or by using code behind files. Since in SharePoint-hosted app, any server side code is not allowed, thus SharePoint content can be accessed using the following ways:
  1. Using client side object model via JavaScript
  2. Calling REST based APIs via JavaScript
In the above hello world app, the logged in user’s name is fetched using the following CSOM code in App.js:


Debugging SharePoint-Hosted App via F5

Once you’re done with the development of your app, you can directly hit the F5 key, its going to package your source files to install the SharePoint app on the target test site. Visual Studio then starts a session of IE, and direct you to the start page of the page, Also, note when you close the session of IE, Visual Studio starts the uninstallation and retraction process of app from the target SharePoint site. Please note that when you hit F5, Visual studio attaches the JavaScript debugger as well to IE, because of which you can directly debug the JavaScript files inside Visual Studio. However, if you would like to use JavaScript debugger built into IE (i.e. IE Developer Tools), just use Ctrl F5 instead of F5.

Sharepoint 2013 Apps hosting - Part 3

Có hai kiểu tùy chọn cho hosting Apps:
  • Sharepoint-hosted
  • Cloud-hosted
    • Provider-hosted
    • Auto-hosted
 Sharepoint-hosted Apps:





Sharepoint-hosted apps chạy trong ngữ cảnh của SP, không có server-side code. Tất cả business chạy trên client, sử dụng javascript. Bạn có thể kế thừa các thành phần SP sẵn có: lists, document libraries, pages mà không cần đến code-behind.

Cloud-hosted Apps:


Logic được thực hiện bên ngoài SP, giao tiếp với SP thông qua CSOM hoặc REST services và phải được phân quyền thông qua OAuth.


Giới thiệu mô hình Sharepoint 2013 Apps (Add-Ins) - Part 2

Một số điểm chính:
  • Mọi thứ trên Sharepoint bây giờ là Apps
  • Không tùy biến mã nguồn trên Sharepoint server
  • Dễ dàng nâng cấp các phiên bản
  • Giảm nặng nề về môi trường cho các nhà phát triển
  • Triển khai và cài đặt Apps trên nhiều môi trường
  • Apps là một tùy chọn (không phải thay thế) các mô hình phát triển cũ (Fully trusted solutions, Sandboxed solutions)
Bảng so sánh


Farm Solutions
Sandboxed Solutions
SharePoint Apps
Khi nào cần phát triển

Sử dụng farm solutions chỉ khi bạn không thể thỏa mãn yêu cầu với Apps
Giải pháp Sandboxed  không được khuyến khích trong phiên bản Sharepoint 2013 nhưng nó vẫn có thể được càn đặt vào site collections.
Được khuyến khích là giải pháp đầu tiên nghĩ đến nếu nó có thể giải quyết yêu cầu.
Sử dụng server-side API
Cho phép nhà phát triển có thể viết code để sử dụng server-side API Server-side code có thể được thực thi dưới một chính sách giới hạn. Ngăn cấm hoàn toàn việc thực thi code server-side trong Apps. Mọi code server-side cần được thực thi và host bên ngoài Sharepoint server, trong các hệ thống trung gian
Sử dụng Client-Side API


Có, khả năng hỗ trợ như các phiên bản trước
Triển khai, cài đặt Mã tùy biến được biên dịch và triển khai trong thư mục BIN hoặc GAC.
Có thể được đóng gói và tải lên. Có một số giới hạn/khó khăn khi sử dụng dữ liệu ở các thành phần khác. Dễ dàng
Hosted Deployment and Cloud support
Không hỗ trợ
Sandboxed solutions are the only type of solution that can be deployed to hosted SharePoint installations.
Có. Thậm chí dễ dàng chia sẻ các Apps để cài đặt lên các hệ thống khác nhau.
Install/Upgrade/Uninstall
Làm thủ công
Làm thủ công
Dễ dàng cài đặt và gỡ bỏ
Server Outages
Ảnh hưởng tới toàn bộ hệ thống Chạy độc lập và ít ảnh hưởng hơn
Hoàn toàn độc lập và không ảnh hưởng tới các thành phần khác của hệ thống
Authentication Options
Các thành phần chạy dưới chế độ full trust.
Các thành phần chạy dưới chế độ partial trust.



Trước khi bạn gọi SharePoint APIs từ app, bạn cần chứng thực với Sharepoint. Cơ chế chứng thực bạn sử dụng tùy thuộc vào khu vực cài đặt app: 
  • Bên trong Sharepoint: Bạn sửu dụng HTML, Js và cơ chế chứng thực sẽ làm giúp bạn.  
  • Với môi trường Cloud:   
    • Sử dụng client-side code với thư viện cross-domain.
    • Sử dụng server-side code với OAuth
    • REST APIs
 
Có thể phát triển những gì
Hầu như tất cả
Một vài cái mà sandbox không hỗ trợ
  • Kết nối tới tài nguyên không nawmgf trong farm.
  • Truy cập database
  • Gọi unmanaged code
  • Ghi vào đĩa cứng  
  • Truy cập tài nguyên trong site khác
Có thể:
  • Tùy biến Web Parts   
  • Nhận sự kiện
  • Tùy biến trường dữ liệu
  • Tùy biến web services trên SP Service Application Framwork Application pages 
Không thể
  • Tùy biến site
  • Tùy biến themes
  • Tùy biến hành động groups và tùy biến hành động ẩn trong User Control (ascx file)
  • Delegate controls

Khái niệm Apps (add - ins) trong Sharepoint 2013 - Part 1

Trong các phiên bản trước Sharepoint 2013 đã có rất nhiều khái niệm đặc thù như (pages, lists, libraries, sites, web parts, master pages...). Nó khá phức tạp cho người mới bắt đầu tiếp cận Sharepoint. Đôi khi người dùng cảm thấy lẫn lộn giữa các thành phần được hiển thị ở phần ribbon và điều hướng (navigation). Lý do dẫn đến việc này là Sharepoint được dùng với quá nhiều mục đích nên thói quen làm việc với ứng dụng web trên Sharepoint rất khác so với các ứng dụng web khác. Với phiên bản mới Sharepoint 2013, Microsoft muốn tạo ra các khái niệm dễ dàng hơn cho người dùng.

Tại sao cần thiết Apps (Add Ins)
Trong các công nghệ web mới, gadgets, smart phone... đang ngày càng phổ biến, người dùng dần quen thuộc với các khái niệm như: Sites, People, Apps, Themes. Phiên bản Sharepoint 2013 chủ yếu tập trung trên 4 khái niệm chính đó (Sites, People, Apps, Themes) để người dùng dễ dàng sử dụng và cảm thấy quen thuộc.
Với người dùng cuối, các khái niệm này được mô tả ngắn gọi như sau:
  • Sites: Một nơi lưu trữ các nội dung (pages, documents, list items)
  • People: Cho phép người dùng truy cập các nội dung và trao đổi với người dùng khác trong cùng một không gian làm việc cộng tác (collaboration)
  • Apps: Cung cấp chức năng cho site. Nó có thể là mọi thứ: web part, document library,...
  • Themes: Nâng cao khả năng trình bày nội dung trong site (look and feel)
Trong Sharepoint 2010, đã có 3 trong 4 khái niệm trên (Site, People, Themes). Nhưng chưa có khái niệm Apps - cung cấp những chức năng riêng biệt mà người dùng đã khá quen thuộc như khi sử dụng các nền tảng khác (phone, tablet). Thiếu sót này cần được khắc phục cho phù hợp với xu thế mới.

Thách thức với Sharepoint 2010
Đã có một số vấn đề thấy được trên SP 2010, sự mất ổn định khi hoạt động trên farm và rất khó để migrate lên phiên bản mới. Giải pháp Sharepoint farm yêu cầu triển khai đóng gói. Có rất nhiều mã nguồn được phát triển trên SP2010 server, và nếu nó không được viết tốt, sẽ vô cùng khó khăn để migrate.
Một phương án để cố gắng giải quyết tình huống này là sử dụng giải pháp sandbox, nhưng nó thật sự có những giới hạn của riêng nó và thật tế cũng ít khách hàng sử dụng giải pháp này một cách trơn tru.

Mô hình Sharepoint 2013 Apps
Mô hình mới trong Sharepoint 2013 không chỉ loại bỏ vấn đề giải pháp đóng gói, tùy biến mã nguồn trên server mà còn giới thiệu nhiều tính năng cải tiến mới.
Sharepoint 2013 Apps không được triển khai trên server, IIS hay Azure mà trên phía client. Apps được phân quyền thông quan OAuth và giao tiếp với Sharepoint thông qua REST APIs hoặc CSOM (Client Side Object Model)
Các nhà phát triển có thể xuất bản Apps của họ lên trên market để mọi người có thể mua và tải về dùng.