├── .gitignore
├── LICENSE
├── README.md
├── SharePoint-Add-in-JSOM-CrossDomain.sln
├── SharePoint-Add-in-JSOM-CrossDomain
├── Announcements
│ ├── Elements.xml
│ └── SharePointProjectItem.spdata
├── AppIcon.png
├── AppManifest.xml
├── Features
│ └── Feature1
│ │ ├── Feature1.Template.xml
│ │ └── Feature1.feature
├── Package
│ ├── Package.Template.xml
│ └── Package.package
└── SharePoint-Add-in-JSOM-CrossDomain.csproj
├── SharePoint-Add-in-JSOM-CrossDomainWeb
├── Pages
│ └── CrossDomainCall.aspx
├── Properties
│ └── AssemblyInfo.cs
├── Scripts
│ ├── CrossDomainExec.js
│ └── _references.js
├── SharePoint-Add-in-JSOM-CrossDomainWeb.csproj
├── Web.config
└── packages.config
└── description
└── image.png
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | build/
21 | bld/
22 | [Bb]in/
23 | [Oo]bj/
24 |
25 | # Visual Studo 2015 cache/options directory
26 | .vs/
27 |
28 | # MSTest test Results
29 | [Tt]est[Rr]esult*/
30 | [Bb]uild[Ll]og.*
31 |
32 | # NUNIT
33 | *.VisualState.xml
34 | TestResult.xml
35 |
36 | # Build Results of an ATL Project
37 | [Dd]ebugPS/
38 | [Rr]eleasePS/
39 | dlldata.c
40 |
41 | *_i.c
42 | *_p.c
43 | *_i.h
44 | *.ilk
45 | *.meta
46 | *.obj
47 | *.pch
48 | *.pdb
49 | *.pgc
50 | *.pgd
51 | *.rsp
52 | *.sbr
53 | *.tlb
54 | *.tli
55 | *.tlh
56 | *.tmp
57 | *.tmp_proj
58 | *.log
59 | *.vspscc
60 | *.vssscc
61 | .builds
62 | *.pidb
63 | *.svclog
64 | *.scc
65 |
66 | # Chutzpah Test files
67 | _Chutzpah*
68 |
69 | # Visual C++ cache files
70 | ipch/
71 | *.aps
72 | *.ncb
73 | *.opensdf
74 | *.sdf
75 | *.cachefile
76 |
77 | # Visual Studio profiler
78 | *.psess
79 | *.vsp
80 | *.vspx
81 |
82 | # TFS 2012 Local Workspace
83 | $tf/
84 |
85 | # Guidance Automation Toolkit
86 | *.gpState
87 |
88 | # ReSharper is a .NET coding add-in
89 | _ReSharper*/
90 | *.[Rr]e[Ss]harper
91 | *.DotSettings.user
92 |
93 | # JustCode is a .NET coding addin-in
94 | .JustCode
95 |
96 | # TeamCity is a build add-in
97 | _TeamCity*
98 |
99 | # DotCover is a Code Coverage Tool
100 | *.dotCover
101 |
102 | # NCrunch
103 | _NCrunch_*
104 | .*crunch*.local.xml
105 |
106 | # MightyMoose
107 | *.mm.*
108 | AutoTest.Net/
109 |
110 | # Web workbench (sass)
111 | .sass-cache/
112 |
113 | # Installshield output folder
114 | [Ee]xpress/
115 |
116 | # DocProject is a documentation generator add-in
117 | DocProject/buildhelp/
118 | DocProject/Help/*.HxT
119 | DocProject/Help/*.HxC
120 | DocProject/Help/*.hhc
121 | DocProject/Help/*.hhk
122 | DocProject/Help/*.hhp
123 | DocProject/Help/Html2
124 | DocProject/Help/html
125 |
126 | # Click-Once directory
127 | publish/
128 |
129 | # Publish Web Output
130 | *.[Pp]ublish.xml
131 | *.azurePubxml
132 | # TODO: Comment the next line if you want to checkin your web deploy settings
133 | # but database connection strings (with potential passwords) will be unencrypted
134 | *.pubxml
135 | *.publishproj
136 |
137 | # NuGet Packages
138 | *.nupkg
139 | # The packages folder can be ignored because of Package Restore
140 | **/packages/*
141 | # except build/, which is used as an MSBuild target.
142 | !**/packages/build/
143 | # Uncomment if necessary however generally it will be regenerated when needed
144 | #!**/packages/repositories.config
145 |
146 | # Windows Azure Build Output
147 | csx/
148 | *.build.csdef
149 |
150 | # Windows Store app package directory
151 | AppPackages/
152 |
153 | # Others
154 | *.[Cc]ache
155 | ClientBin/
156 | [Ss]tyle[Cc]op.*
157 | ~$*
158 | *~
159 | *.dbmdl
160 | *.dbproj.schemaview
161 | *.pfx
162 | *.publishsettings
163 | node_modules/
164 | bower_components/
165 |
166 | # RIA/Silverlight projects
167 | Generated_Code/
168 |
169 | # Backup & report files from converting an old project file
170 | # to a newer Visual Studio version. Backup files are not needed,
171 | # because we have git ;-)
172 | _UpgradeReport_Files/
173 | Backup*/
174 | UpgradeLog*.XML
175 | UpgradeLog*.htm
176 |
177 | # SQL Server files
178 | *.mdf
179 | *.ldf
180 |
181 | # Business Intelligence projects
182 | *.rdl.data
183 | *.bim.layout
184 | *.bim_*.settings
185 |
186 | # Microsoft Fakes
187 | FakesAssemblies/
188 |
189 | # Node.js Tools for Visual Studio
190 | .ntvs_analysis.dat
191 |
192 | # Visual Studio 6 build log
193 | *.plg
194 |
195 | # Visual Studio 6 workspace options file
196 | *.opt
197 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Office
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | page_type: sample
3 | products:
4 | - office-sp
5 | - office-365
6 | languages:
7 | - javascript
8 | extensions:
9 | contentType: samples
10 | technologies:
11 | - Add-ins
12 | - OAuth 2.0
13 | createdDate: 8/12/2015 1:15:58 PM
14 | description: "Use the SharePoint Cross Domain JavaScript library to access SharePoint data from a remotely hosted web page without the need for OAuth tokens."
15 | ---
16 |
17 | # Access SharePoint data with the Cross Domain JavaScript Library
18 |
19 | > SharePoint add-in model is considered as a legacy option for extending SharePoint user interface. Please see [SharePoint Framework documentation](https://aka.ms/spfx) and the [SharePoint Framework samples](https://aka.ms/spfx-webparts) for the future proven option to extend SharePoint Online. Possible backend services should be using Azure Active Directly based registration and related app models.
20 |
21 | ## Summary
22 |
23 | Use the SharePoint Cross Domain JavaScript library (CDL) to access SharePoint data from a remotely hosted web page without the need for OAuth tokens.
24 |
25 | ### Applies to
26 |
27 | - SharePoint Online and on-premise SharePoint 2013 and later
28 |
29 | ## Prerequisites
30 |
31 | This sample requires the following:
32 |
33 | - A SharePoint 2013 (or later) development environment that is configured for add-in isolation. (A SharePoint Online Developer Site is automatically configured. For an on premise development environment, see [Set up an on-premises development environment for SharePoint Add-ins](https://msdn.microsoft.com/library/office/fp179923.aspx))
34 |
35 | - Visual Studio and the Office Developer Tools for Visual Studio installed on your developer computer
36 |
37 | ## Description of the code
38 |
39 | The sample includes an instance of an Announcements list with two sample announcements in it. The list instance is deployed to the add-in web. When the start page loads, JavaScript in the CrossDomainExec.js file, in the remote domain, makes an AJAX call to SharePoint to get the announcements and displays them on the page.
40 |
41 | The page looks similar to the following.
42 |
43 | 
44 |
45 | **Note:** The start page of the add-in, CrossDomainCall.aspx, is a plain HTML file. It has an "aspx" extension because when a remote start page in a provider-hosted add-in is opened by SharePoint, SharePoint sends it a context token in the body of the HTTP request. To do this SharePoint must send a POST request. But the IIS Express that is hosting the remote page when you are debugging will not accept POST requests to a resource with a .html extension.
46 |
47 | The sample demonstrates the following:
48 |
49 | - How to use the key classes of the CDL to make calls from a remotely hosted domain to the SharePoint add-in web domain.
50 |
51 | - How to parse the JSON-formatted data returned from the SharePoint and how to display it dynamically.
52 |
53 | ## To use the sample
54 |
55 | 12. Open **Visual Studio** as an administrator.
56 | 13. Open the .sln file.
57 | 13. In **Solution Explorer**, highlight the SharePoint add-in project and replace the **Site URL** property with the URL of your SharePoint developer site.
58 | 14. Press F5.
59 | 15. After the add-in installs, the consent page opens. Click **Trust It**.
60 | 16. The page opens that the JavaScript runs immediately.
61 |
62 |
63 | ## Troubleshooting
64 |
65 | For troubleshooting steps, visit the "Troubleshooting the solution" table in the [cross-domain library documentation article](http://msdn.microsoft.com/library/bc37ff5c-1285-40af-98ae-01286696242d).
66 |
67 | ## Questions and comments
68 |
69 | We'd love to get your feedback on this sample. You can send your questions and suggestions to us in the [Issues](https://github.com/OfficeDev/SharePoint-Add-in-JSOM-CrossDomain/issues) section of this repository.
70 |
71 |
72 | ## Additional resources
73 |
74 | - [SharePoint Add-ins](https://msdn.microsoft.com/library/office/fp179930.aspx )
75 | - [Creating SharePoint Add-ins that use the cross-domain library](https://msdn.microsoft.com/library/office/dn790708.aspx)
76 | - [Access SharePoint 2013 data from add-ins using the cross-domain library](https://msdn.microsoft.com/library/office/fp179927.aspx)
77 |
78 | ### Copyright
79 |
80 | Copyright (c) Microsoft. All rights reserved.
81 |
82 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information, see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
83 |
--------------------------------------------------------------------------------
/SharePoint-Add-in-JSOM-CrossDomain.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.23107.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharePoint-Add-in-JSOM-CrossDomain", "SharePoint-Add-in-JSOM-CrossDomain\SharePoint-Add-in-JSOM-CrossDomain.csproj", "{948D5FE7-9CB6-43E6-93DB-4569ECFF1E90}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharePoint-Add-in-JSOM-CrossDomainWeb", "SharePoint-Add-in-JSOM-CrossDomainWeb\SharePoint-Add-in-JSOM-CrossDomainWeb.csproj", "{3A09D2C6-FF22-4F35-9718-A7D7FEDBA01C}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {948D5FE7-9CB6-43E6-93DB-4569ECFF1E90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {948D5FE7-9CB6-43E6-93DB-4569ECFF1E90}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {948D5FE7-9CB6-43E6-93DB-4569ECFF1E90}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
19 | {948D5FE7-9CB6-43E6-93DB-4569ECFF1E90}.Release|Any CPU.ActiveCfg = Release|Any CPU
20 | {948D5FE7-9CB6-43E6-93DB-4569ECFF1E90}.Release|Any CPU.Build.0 = Release|Any CPU
21 | {948D5FE7-9CB6-43E6-93DB-4569ECFF1E90}.Release|Any CPU.Deploy.0 = Release|Any CPU
22 | {3A09D2C6-FF22-4F35-9718-A7D7FEDBA01C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {3A09D2C6-FF22-4F35-9718-A7D7FEDBA01C}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {3A09D2C6-FF22-4F35-9718-A7D7FEDBA01C}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {3A09D2C6-FF22-4F35-9718-A7D7FEDBA01C}.Release|Any CPU.Build.0 = Release|Any CPU
26 | EndGlobalSection
27 | GlobalSection(SolutionProperties) = preSolution
28 | HideSolutionNode = FALSE
29 | EndGlobalSection
30 | EndGlobal
31 |
--------------------------------------------------------------------------------
/SharePoint-Add-in-JSOM-CrossDomain/Announcements/Elements.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
11 |
12 | Great News
13 | I became a grandfather yesterday!
14 |
15 |
16 | Version 1 Shipped!
17 | We shipped version 1 to European markets.
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/SharePoint-Add-in-JSOM-CrossDomain/Announcements/SharePointProjectItem.spdata:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/SharePoint-Add-in-JSOM-CrossDomain/AppIcon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/SharePoint-Add-in-JSOM-CrossDomain/91b238d9056b1f4604533c49117dc4bd295ef1ea/SharePoint-Add-in-JSOM-CrossDomain/AppIcon.png
--------------------------------------------------------------------------------
/SharePoint-Add-in-JSOM-CrossDomain/AppManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 | SharePoint-Add-in-JSOM-CrossDomain
11 | ~remoteAppUrl/Pages/CrossDomainCall.aspx?{StandardTokens}
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/SharePoint-Add-in-JSOM-CrossDomain/Features/Feature1/Feature1.Template.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/SharePoint-Add-in-JSOM-CrossDomain/Features/Feature1/Feature1.feature:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/SharePoint-Add-in-JSOM-CrossDomain/Package/Package.Template.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/SharePoint-Add-in-JSOM-CrossDomain/Package/Package.package:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/SharePoint-Add-in-JSOM-CrossDomain/SharePoint-Add-in-JSOM-CrossDomain.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {948D5FE7-9CB6-43E6-93DB-4569ECFF1E90}
8 | Library
9 | Properties
10 | SharePoint_Add_in_JSOM_CrossDomain
11 | SharePoint-Add-in-JSOM-CrossDomain
12 | v4.5
13 | 15.0
14 | 512
15 | {C1CDDADD-2546-481F-9697-4EA41081F2FC};{14822709-B5A1-4724-98CA-57A101D1B079};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
16 | 11.0
17 | 11.1
18 | False
19 | SharePointApp
20 | {3bee7677-809d-4fcc-894d-14ce2c3c1584}
21 | {0975bfd5-d411-4e6f-8f20-e1beec1814bd}
22 | {ec08e0ca-486a-4609-a8a1-45c64fa98b88}
23 | {d16132b6-9084-42f3-95d2-1546ae55d21f}
24 | {13612784-b319-416a-be28-3e5ec6a291a2}
25 |
26 |
27 | true
28 | full
29 | false
30 | bin\Debug\
31 | DEBUG;TRACE
32 | prompt
33 | 4
34 | false
35 |
36 |
37 | pdbonly
38 | true
39 | bin\Release\
40 | TRACE
41 | prompt
42 | 4
43 | false
44 |
45 |
46 |
47 |
48 | manifest-icon
49 |
50 |
51 | Feature1.feature
52 |
53 |
54 | Package.package
55 |
56 |
57 |
58 |
59 | Designer
60 |
61 |
62 |
63 |
64 | {3A09D2C6-FF22-4F35-9718-A7D7FEDBA01C}
65 | SharePoint-Add-in-JSOM-CrossDomainWeb
66 | True
67 | Web
68 | SharePointWebProjectOutput
69 | SharePoint-Add-in-JSOM-CrossDomainWeb
70 | False
71 |
72 |
73 |
74 |
75 | {95bbc89c-b7b6-4bd3-8b6d-b21445c19cd5}
76 |
77 |
78 | {78e620ab-f40f-4c01-80a5-a471110d5123}
79 |
80 |
81 | {3b00cae6-b717-43bc-8156-50991bf5e046}
82 |
83 |
84 |
85 |
86 | 10.0
87 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
88 |
89 |
90 |
--------------------------------------------------------------------------------
/SharePoint-Add-in-JSOM-CrossDomainWeb/Pages/CrossDomainCall.aspx:
--------------------------------------------------------------------------------
1 | <%-- Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. --%>
2 |
3 |
4 |
5 |
6 |
7 |
8 | SharePoint Add-in Sample for Cross Domain Data Access with the JavaScript Object Model
9 |
10 |
11 |
12 |
13 |
14 |
18 |
22 |
26 |
27 |
28 | <%--
29 |
30 | SharePoint-Add-in-JSOM-CrossDomain, https://github.com/OfficeDev/SharePoint-Add-in-JSOM-CrossDomain
31 |
32 | Copyright (c) Microsoft Corporation
33 | All rights reserved.
34 |
35 | MIT License:
36 | Permission is hereby granted, free of charge, to any person obtaining
37 | a copy of this software and associated documentation files (the
38 | "Software"), to deal in the Software without restriction, including
39 | without limitation the rights to use, copy, modify, merge, publish,
40 | distribute, sublicense, and/or sell copies of the Software, and to
41 | permit persons to whom the Software is furnished to do so, subject to
42 | the following conditions:
43 |
44 | The above copyright notice and this permission notice shall be
45 | included in all copies or substantial portions of the Software.
46 |
47 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
48 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
50 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
51 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
52 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
53 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
54 |
55 | --%>
--------------------------------------------------------------------------------
/SharePoint-Add-in-JSOM-CrossDomainWeb/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("SharePoint_Add_in_JSOM_CrossDomainWeb")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("SharePoint_Add_in_JSOM_CrossDomainWeb")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("3a09d2c6-ff22-4f35-9718-a7d7fedba01c")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Revision and Build Numbers
33 | // by using the '*' as shown below:
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/SharePoint-Add-in-JSOM-CrossDomainWeb/Scripts/CrossDomainExec.js:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file.
2 |
3 |
4 | // The allAnnouncements variable is used by more than one
5 | // function to retrieve and process the results.
6 | var allAnnouncements;
7 | var hostweburl;
8 | var addinweburl;
9 |
10 | // Load the required SharePoint libraries
11 | $(document).ready(function () {
12 | //Get the URI decoded URLs.
13 | hostweburl =
14 | decodeURIComponent(
15 | getQueryStringParameter("SPHostUrl")
16 | );
17 | addinweburl =
18 | decodeURIComponent(
19 | // The parameter is SPAppWebUrl, not SPAdd-inWebUrl because add-ins were originally called "apps".
20 | getQueryStringParameter("SPAppWebUrl")
21 | );
22 |
23 | // resources are in URLs in the form:
24 | // web_url/_layouts/15/resource
25 | var scriptbase = hostweburl + "/_layouts/15/";
26 |
27 | // Load the js files and continue to the successHandler
28 | $.getScript(scriptbase + "SP.Runtime.js",
29 | function () {
30 | $.getScript(scriptbase + "SP.js",
31 | function () { $.getScript(scriptbase + "SP.RequestExecutor.js", execCrossDomainRequest); }
32 | );
33 | }
34 | );
35 | });
36 |
37 | // Function to prepare and issue the request to get
38 | // SharePoint data
39 | function execCrossDomainRequest() {
40 | // context: The ClientContext object provides access to
41 | // the web and lists objects.
42 | // factory: Initialize the factory object with the
43 | // app web URL.
44 | var context = new SP.ClientContext(addinweburl);
45 | var factory =
46 | new SP.ProxyWebRequestExecutorFactory(
47 | addinweburl
48 | );
49 | context.set_webRequestExecutorFactory(factory);
50 |
51 | //Get the web and list objects
52 | // and prepare the query
53 | var web = context.get_web();
54 | var list = web.get_lists().getByTitle("Announcements");
55 | var camlString =
56 | "" +
57 | "" +
58 | "" +
59 | "";
60 |
61 | var camlQuery = new SP.CamlQuery();
62 | camlQuery.set_viewXml(camlString);
63 | allAnnouncements = list.getItems(camlQuery);
64 |
65 | context.load(allAnnouncements, "Include(Title, Body)");
66 |
67 | //Execute the query with all the previous
68 | // options and parameters
69 | context.executeQueryAsync(
70 | successHandler, errorHandler
71 | );
72 | }
73 |
74 | // Function to handle the success event.
75 | // Prints the data to the page.
76 | function successHandler(data, req) {
77 | var announcementsHTML = "";
78 | var enumerator = allAnnouncements.getEnumerator();
79 |
80 | while (enumerator.moveNext()) {
81 | var announcement = enumerator.get_current();
82 | announcementsHTML = announcementsHTML +
83 | "" + announcement.get_item("Title") +
84 | "
" + announcement.get_item("Body") +
85 | "
";
86 | }
87 |
88 | document.getElementById("renderAnnouncements").innerHTML =
89 | announcementsHTML;
90 | }
91 |
92 | // Function to handle the error event.
93 | // Prints the error message to the page.
94 | function errorHandler(data, error, errorMessage) {
95 | document.getElementById("renderAnnouncements").innerText =
96 | "Could not complete cross-domain call: " +
97 | errorMessage;
98 | }
99 |
100 | // Function to retrieve a query string value.
101 | // For production purposes you may want to use
102 | // a library to handle the query string.
103 | function getQueryStringParameter(paramToRetrieve) {
104 | var params =
105 | document.URL.split("?")[1].split("&");
106 | var strParams = "";
107 | for (var i = 0; i < params.length; i = i + 1) {
108 | var singleParam = params[i].split("=");
109 | if (singleParam[0] == paramToRetrieve)
110 | return singleParam[1];
111 | }
112 | }
113 |
114 | /*
115 |
116 | SharePoint-Add-in-JSOM-CrossDomain, https://github.com/OfficeDev/SharePoint-Add-in-JSOM-CrossDomain
117 |
118 | Copyright (c) Microsoft Corporation
119 | All rights reserved.
120 |
121 | MIT License:
122 | Permission is hereby granted, free of charge, to any person obtaining
123 | a copy of this software and associated documentation files (the
124 | "Software"), to deal in the Software without restriction, including
125 | without limitation the rights to use, copy, modify, merge, publish,
126 | distribute, sublicense, and/or sell copies of the Software, and to
127 | permit persons to whom the Software is furnished to do so, subject to
128 | the following conditions:
129 |
130 | The above copyright notice and this permission notice shall be
131 | included in all copies or substantial portions of the Software.
132 |
133 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
134 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
135 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
136 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
137 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
138 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
139 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
140 |
141 | */
--------------------------------------------------------------------------------
/SharePoint-Add-in-JSOM-CrossDomainWeb/Scripts/_references.js:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/SharePoint-Add-in-JSOM-CrossDomainWeb/SharePoint-Add-in-JSOM-CrossDomainWeb.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Debug
8 | AnyCPU
9 |
10 |
11 | 2.0
12 | {3A09D2C6-FF22-4F35-9718-A7D7FEDBA01C}
13 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
14 | Library
15 | Properties
16 | SharePoint_Add_in_JSOM_CrossDomainWeb
17 | SharePoint-Add-in-JSOM-CrossDomainWeb
18 | v4.5
19 | true
20 | 44300
21 |
22 |
23 |
24 |
25 |
26 |
27 | 15.0
28 |
29 |
30 | true
31 | full
32 | false
33 | bin\
34 | DEBUG;TRACE
35 | prompt
36 | 4
37 |
38 |
39 | pdbonly
40 | true
41 | bin\
42 | TRACE
43 | prompt
44 | 4
45 |
46 |
47 |
48 | ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll
49 | True
50 |
51 |
52 |
53 | True
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | Web.config
81 |
82 |
83 | Web.config
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 | 10.0
98 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 | True
108 | True
109 | 45440
110 | /
111 | http://localhost:45440/
112 | False
113 | False
114 |
115 |
116 | False
117 |
118 |
119 |
120 |
121 |
122 |
123 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
124 |
125 |
126 |
127 |
128 |
135 |
--------------------------------------------------------------------------------
/SharePoint-Add-in-JSOM-CrossDomainWeb/Web.config:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/SharePoint-Add-in-JSOM-CrossDomainWeb/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/description/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OfficeDev/SharePoint-Add-in-JSOM-CrossDomain/91b238d9056b1f4604533c49117dc4bd295ef1ea/description/image.png
--------------------------------------------------------------------------------