Thursday, August 3, 2017

Anonymous Access for Client Object Model in SharePoint

Have you ever faced this error failed Message: The method “GetItems” of the type “List” with ID {GUID} is blocked by administrator on the server.on public facing site ?

So apparently anonymous users, using the Client Object Model, are blocked from using

    GetItems and GetChanges on SPLists
    GetChanges and GetSubwebsForCurrentUser on SPWebs
    GetChanges on SPSites

The good news, however, is that the ClientCallableSettings value can be adjusted to allow anonymous user access to one or more of these methods.
Doing this with PowerShell:
$webapp = Get-SPWebApplication "http://sp2013dev"
$webapp.ClientCallableSettings.AnonymousRestrictedTypes.Remove([microsoft.sharepoint.splist], "GetItems")
$webapp.Update()
Be sure to replace "http://sp2013dev" with whatever url your target webapp has. After doing this, anonymous calls to GetItems will work for that web application. The changes are persisted in the SharePoint database, and last until you change the setting again, or recreate the web application.

Monday, April 10, 2017

Deploy SPFx client side web part through CDN

In this article, you will deploy the client side webpart to a SharePoint Library. SharePoint Framework build tools provide out-of-the-box support for deploying to an Azure Storage account, but this involved extra cost. Azure Storage account is the best practice to maintain our webpart.

Prerequisites
  1. Setup SharePoint Tenant
  2. Setup your machine
  3. First Webpart
In this article I am showing how to deploy a client side web part in SharePoint Library.
Step 1: Create Webpart
Follow Link for webpart creation: https://sharedpointtips.blogspot.com/2017/04/sharepoint-framework-spfx-app.html
  • Create a new Webpart, I named here “spfx-firstwebpart”
  • md spfx-firstwebpart
  • cd spfx-firstwebpart
  • Create new Webpart yo @microsoft/sharepoint
It will create a new Webpart refer below screenshot
deploysp1deploysp2

Build the Webpart gulp serve
Step 2: Create SharePoint Library
  • Create a SharePoint Library “Myspfxwebparts” and give read permission to all users.
Step 3: Open code Visual Studio Code
  • Open the code in Visual code tool.
  • Type in cmd : code .
Step 4: Update the CDN Path
  • We need to configure the CDN path, i.e SharePoint Library what we created. https://jenkinsblogs.sharepoint.com/sites/dev/Myspfxwebparts
  • we have to configure our CDN path in write-manifests.json file. This file can be found in the config folder.
  • i.e
{
  “cdnBasePath”: “https://jenkinsblogs.sharepoint.com/sites/dev/Myspfxwebparts”
}
  • Save the file.
  • Switch to cmd prompt
Step 5: Package and Deploy the webpart
  • Generate the files to deploy in the SharePoint Library
    • gulp bundle –ship
    • Generated files can be found in spfx-firstwebpart\temp\deploy folder
    • upload the files in the SharePoint Library
      • https://jenkinsblogs.sharepoint.com/sites/dev/Myspfxwebparts
  • Create a .spapp file for this webpart to upload in App Catalog
    • gulp package-solution –ship
    • Generated spapp file can be found in spfx-firstwebpart\sharepoint folder
    • upload the spapp file in App catalog
    • SharePoint will show you a popup and ask you to trust the client-side solution to deploy.
    • Click Deploy
Step 6: Install the App
  • Open your SharePoint Site
  • Go to “Add an App”
  • Click “From Your Organization”
  • Select and Click you app to install it.
Syep 7: Add the Webpart in your Page
  • After App installation
  • Go to your Page
  • Edit the Page
  • Click Insert tab and click Webpart
  • Select Custom folder –> you can see your webpart, refer below screenshot
deploysp3
  • Now you can add your webpart
    • Select the your webpart and Click Add
    • It will add your webpart
deploysp4

SharePoint Framework (SPFx) App Development

Hopefully by now you heard that the new SharePoint Framework (SPFx) has been released in preview. The original blog post from Microsoft can be found here.
This is a milestone for the SharePoint Development Team, as it now begins the transition to what they demonstrated back on May 4th for SharePoint. The new framework is comprised of a few components, if you are using Windows like me then you will need the following:
If you are using Visual Studio:
Once you have all of these installed, you can then follow the core instruction provided by Microsoft over at the GitHub Wiki.
As a note for me running Windows 10, I ended up having a missing package that manifested itself at runtime. Top resolve this I ran: npm install es6-promise
This might not make any sense if you have never run NodeJS on your machine before. NodeJS is a great platform for development using JavaScript code and can be used for more than just the SharePoint Framework, however in order to be able to develop completely offline an engine was needed that would allow an empty SharePoint type interface to be launched.
Under the covers of the SharePoint Framework, core Web Development components are used which makes a change from the standard SharePoint Development approaches we have been used to. To get started you still need to download a few things and that is done from within the NodeJS command line interface. This launched from your start menu easily.

Once the command line loads it should look like this or similar.

The location really means nothing as you will be moving around anyway. The core command you will use here is “npm” which is the package manager for getting the modules that you need. The documentation runs through the following commands to get what you need:

npm install -g npm

npm i -g yo gulp

npm i -g @microsoft/generator-sharepoint


These commands will setup the scaffolding you need, using Yeoman Generator and then Gulp for Build and Task Management. Then the Generator project itself provided by Microsoft. Once you have everything setup, you can follow the next document that is provided and bring down the sample web part using the following command:

yo @microsoft/sharepoint




It will ask you a few more questions and then you are ready to complete the wizard, choosing what JavaScript Framework to use etc.

Once you have complete the core questions it will then go ahead and create what is needed, within the directory you specified.

It will take some time to complete as it downloads any dependencies and creates the core project. As you run this you may see some error, which you can just ignore at this point as they are mostly warnings about versions.

Once it is all completed it should display a nice little message allowing you to either load what it has created using “gulp serve” command to simply load it within Visual Studio or Visual Studio Code.


“Gulp Serve”


Visual Studio Code


Wednesday, January 4, 2017

SharePoint show listview webpart from parent site on subsite in same site collection

Quick no-code Tip - About show listview webpart from parent site on subsite in same site collection.

All you have to do is save your list as a Web Part and then add the Web Part to any other page on your site. It’s surprisingly easy to do and doesn’t require any code. In the following example, I’ll assume you are working with a typical customer list.


Part 1: Save the List View to a Web Part file

  1. In the browser, go to the list and display the default view.
  2. To open the list in SharePoint Designer, in the ribbon, on the List tab in the Manage Views group, click the arrow next to Modify View, and then select Modify in SharePoint Designer (advanced).
  3. In SharePoint Designer, position the insertion point on any part of the list.
  4. Do one of the following:
    • If you have contribute permission and want to save the Web Part as a file, in the ribbon, click the Web Part tab, and in the Save Web Part group, click To File, click Save, enter a meaningful Web Part filename, such as Customers.webpart, and then click Save.
    • If you have site-level permissions and want to add the Web Part to the site Web Part gallery, in the ribbon, click the Web Part tab, and in the Save Web Part group, click To Site Gallery, click Save, enter a meaningful Web Part filename, such as Customers, and then click OK.
  5. When SharePoint Designer displays the following message:
  6. Click Yes. This ensures the list is accessible from any site of the current site collection.

    Part 2: Add the Web Part to another page
To begin, I created a new view on the list that I wanted to share, and exported the .webpart file from the XsltListView. To export the .webpart file, you simple click on Site Actions > Edit Page, and on the List View Web Part context menu click "Export" to save the file to your local machine. Web Part files are simply an XML representation of the properties of the web part, and can be imported back into the Web Parts library at the parent site for reuse throughout your Site Collection.

?
1
2
3
4
5
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
<webParts>
    <metaData>
      <type name="Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
      <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
    </metaData>
    <data>
      <properties>
        <property name="InitialAsyncDataFetch" type="bool">False</property>
        <property name="ChromeType" type="chrometype">Default</property>
        <property name="Title" type="string" />
        <property name="Height" type="string" />
        <property name="CacheXslStorage" type="bool">True</property>
        <property name="ListDisplayName" type="string" null="true" />
        <property name="AllowZoneChange" type="bool">True</property>
        <property name="AllowEdit" type="bool">True</property>
        <property name="XmlDefinitionLink" type="string" />
        <property name="DataFields" type="string" />
        <property name="Hidden" type="bool">False</property>
        <property name="ListName" type="string">{B7B83EDB-714E-47A8-AF42-92A194B09169}</property>
        <property name="NoDefaultStyle" type="string" />
        <property name="AutoRefresh" type="bool">False</property>
        <property name="ViewFlag" type="string">8388613</property>
        <property name="Direction" type="direction">NotSet</property>
        <property name="AutoRefreshInterval" type="int">60</property>
        <property name="AllowConnect" type="bool">True</property>
        <property name="Description" type="string" />
        <property name="AllowClose" type="bool">True</property>
        <property name="ShowWithSampleData" type="bool">False</property>
        <property name="ParameterBindings" type="string">
            &lt;ParameterBinding Name="dvt_sortdir" Location="Postback;Connection"/&gt;
            &lt;ParameterBinding Name="dvt_sortfield" Location="Postback;Connection"/&gt;
            &lt;ParameterBinding Name="dvt_startposition" Location="Postback" DefaultValue=""/&gt;
            &lt;ParameterBinding Name="dvt_firstrow" Location="Postback;Connection"/&gt;
            &lt;ParameterBinding Name="OpenMenuKeyAccessible" Location="Resource(wss,OpenMenuKeyAccessible)" /&gt;
            &lt;ParameterBinding Name="open_menu" Location="Resource(wss,open_menu)" /&gt;
            &lt;ParameterBinding Name="select_deselect_all" Location="Resource(wss,select_deselect_all)" /&gt;
            &lt;ParameterBinding Name="idPresEnabled" Location="Resource(wss,idPresEnabled)" /&gt;
            &lt;ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" /&gt;
            &lt;ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" /&gt;
        </property>
        <property name="Xsl" type="string" null="true" />
        <property name="CacheXslTimeOut" type="int">86400</property>
        <property name="WebId" type="System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">820a89d6-8509-4bc4-9d39-4fd91e420f7a</property>
        <property name="ListUrl" type="string" null="true" />
        <property name="DataSourceID" type="string" />
        <property name="FireInitialRow" type="bool">True</property>
        <property name="ManualRefresh" type="bool">False</property>
        <property name="ViewFlags" type="Microsoft.SharePoint.SPViewFlags, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">Html, TabularView, Mobile</property>
        <property name="ChromeState" type="chromestate">Normal</property>
        <property name="AllowHide" type="bool">True</property>
        <property name="PageSize" type="int">-1</property>
        <property name="SampleData" type="string" null="true" />
        <property name="BaseXsltHashKey" type="string" null="true" />
        <property name="AsyncRefresh" type="bool">False</property>
        <property name="HelpMode" type="helpmode">Modeless</property>
        <property name="ListId" type="System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">b7b83edb-714e-47a8-af42-92a194b09169</property>
        <property name="DataSourceMode" type="Microsoft.SharePoint.WebControls.SPDataSourceMode, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">List</property>
        <property name="AllowMinimize" type="bool">True</property>
        <property name="TitleUrl" type="string">/kb/Lists/Emerging Issues</property>
        <property name="CatalogIconImageUrl" type="string" />
        <property name="DataSourcesString" type="string" />
        <property name="GhostedXslLink" type="string">main.xsl</property>
        <property name="PageType" type="Microsoft.SharePoint.PAGETYPE, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">PAGE_NORMALVIEW</property>
        <property name="DisplayName" type="string">OnlineWPItems</property>
        <property name="UseSQLDataSourcePaging" type="bool">True</property>
        <property name="Width" type="string" />
        <property name="ExportMode" type="exportmode">All</property>
        <property name="XslLink" type="string" null="true" />
        <property name="ViewContentTypeId" type="string">0x</property>
        <property name="HelpUrl" type="string" />
        <property name="XmlDefinition" type="string">&lt;View Name="{863AE444-CE71-4B03-A037-976A884DFA9B}" MobileView="TRUE" Type="HTML" DisplayName="OnlineWPItems" Url="/kb/Lists/Emerging Issues/OnlineWPItems.aspx" Level="1" BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/images/generic.png"&gt;&lt;Query&gt;&lt;OrderBy&gt;&lt;FieldRef Name="Modified" Ascending="FALSE"/&gt;&lt;/OrderBy&gt;&lt;Where&gt;&lt;And&gt;&lt;And&gt;&lt;Contains&gt;&lt;FieldRef Name="Intuit_x0020_Services"/&gt;&lt;Value Type="Text"&gt;Software (SaaS):Online Payroll&lt;/Value&gt;&lt;/Contains&gt;&lt;IsNotNull&gt;&lt;FieldRef Name="Issue_x0020_Status"/&gt;&lt;/IsNotNull&gt;&lt;/And&gt;&lt;Neq&gt;&lt;FieldRef Name="Issue_x0020_Status"/&gt;&lt;Value Type="Text"&gt;Updated&lt;/Value&gt;&lt;/Neq&gt;&lt;/And&gt;&lt;/Where&gt;&lt;GroupBy/&gt;&lt;/Query&gt;&lt;ViewFields&gt;&lt;FieldRef Name="Issue_x0020_Status"/&gt;&lt;FieldRef Name="LinkTitle"/&gt;&lt;/ViewFields&gt;&lt;RowLimit Paged="TRUE"&gt;5&lt;/RowLimit&gt;&lt;Aggregations Value="Off"/&gt;&lt;Toolbar Type="Standard"/&gt;&lt;/View&gt;</property>
        <property name="Default" type="string" />
        <property name="TitleIconImageUrl" type="string" />
        <property name="MissingAssembly" type="string">Cannot import this Web Part.</property>
        <property name="SelectParameters" type="string" />
      </properties>
    </data>
  </webPart>
</webParts>

The highlighted line shows the WebId property in the exported web part file. If you open the file in a text editor or Visual Studio, you can modify the WebId before uploading the new file to your Web Parts Gallery. By default, the WebId is Guid.Empty() or 00000000-0000-0000-0000-000000000000.

To get the WebId, fire up powershell on one of your sharepoint servers and use this snippet:

?
1
2
$web = Get-SPWeb http://[url]
$web.Id

Be sure to include the full path of the web, e.g. if the list is hosted under a subsite it would be http://sharepoint/listlocation.

Now that you have your WebId, copy it from the powershell window and paste it into the WebPart file property "WebId" overwriting the default value. Save the file. 

Uploading the Web Part File
  1. Navigate to the top-level site in your site collection
  2. Click on Site Actions > Site Settings
  3. Click on "Web Parts" under the "Galleries" section
  4. Upload your .webpart file to the Web Part Gallery (Name the file something that will easily be recognizable when adding the web part to your pages. I also tend to organize my web parts into groups, and in this case I've created a new Group called "Cross-site List View Web Parts")
  5. Save your file properties.

At this point you should be at the "Web Part Gallery" items view. From here you can click on the title of your newly added web part to see how it will render on your pages. 

To add the web part to a page in SharePoint, simply edit your page and click the "Add Web Part" option, find the group you created in the "Add Web Part" menu, and click on you web part to add it to the page. Don't forget to save or Checkin your page. If you have publishing enabled, be sure to publish the page so that the changes are available to all users.