Monday 21 December 2015

How to allow READ ONLY/unauthenticated SharePoint users to add an Item in a SharePoint List using an Application Page without giving them “View Application Pages” List Permissions.

Case: I have a SharePoint Site that has a few lists, site pages, application pages etc. One of my application Page was custom coded to allow end users to add an item in a SharePoint List after successful submit a success message was showing using a popup dialog page.

My Permissions are supposed to be set so that end-users should have Read Only permissions and they should not be able to see (i.e. Site Contents to prevent them showing all SharePoint lists or document libraries) any system Pages to system and application pages except the Contact Us and popup dialog so that end users can effectively add a new item in one of the list.

Please note the solution I am describing is one of the possible. There are and can be alternatives to mine. I am merely providing the approach that I have used. My main aim is to do minimum work and get the site working with most of customization. I planned to have a permission set that can allow me to access to Site Pages, and one or more application pages that I deployed. I wanted to make sure that System and other application pages are not accessible. I also wanted end users to have site access.
Hence I have created and customized one permission set and apply it to a group on parent level hence not indulging with breaking Inheritance issues. Finally I used UnsecuredLayoutsPageBase to drive my application pages that I wanted end users to have access.

I have achieved this by following steps:

1.      I created a Permission Level as following
a.      Under List Permissions Only two permissions– Select “Add Items”, it has dependency on “View Items” so let both of them be selected.
b.      Under Site Permissions Only five permissions-> Select “View Pages”, “Browse User Information”, “Use Remote Interfaces”, “Use Client Integration Features” and “Open”.

A note, if I select "View Application Pages" then it works but problem is that you will see other application and system pages as well.

2.      I created a Group and assigned the newly created permission set to it.



4.      I opened my Application and Popup pages and change the code so that they are inherited from UnsecuredLayoutsPageBase rather than SecuredLayoutsPageBase. I also made sure that code that is actually adding an item in the list, is running with Elevated Privilege.


5.      Deploy and test.

Wednesday 9 December 2015

Error while retrieving data from SharePoint 2013 External Content Types: An error occurred while retrieving data from "Name of Secure Store Target Application". Administrators, see the server log for more information.

Error Message: An error occurred while retrieving data from <Name of Secure Store Target Application>. Administrators, see the server log for more information.

Problem: When try to read data from an external data source using SharePoint’s External Content Type functionality. Your users are getting above error. You might have tried to play with Business Data Connectivity Permissions including granting all permissions (Edit, Execute, Selectable In Clients, Permissions) in either/both “Set Object Permissions” or “Set Metadata Store Permissions” but with no success.


Edit
Execute
Selectable In Clients
Set Permissions
http://ipcds0002:45274/_layouts/15/images/blank.gif?rev=23
Propagate permissions to all methods of this external content type. Doing so will overwrite existing permissions.


If above is true then its worth to check your permissions for Secure Store Target Application. You have to update and add your users/group who need to access the data from Secure Store Application into “Members”.

There are essentially two steps to grant permissions on your External Content Types after you successfully created and tested it, so that intended users should be able to use external data.
1.  Make sure you provide “Execute” permission to your users in Central Administration à Manage Service Applications à Business Data Connectivity Service à Double click on it and select your External Content Type à then Click on “Set Object Permissions”à Add your user/group here and assign only “Execute” permission. You can assign more permissions if needed here.
2.  Make sure you provided a mapping of your end users with the credentials you are using to access your external data. Normally you associate one account that will be used by secure store to connect with external data source. Once the connection is successful you have to provide a group/people who can use Secure Store Target Application. In order to do so, you will have to go to Central Administration à Manage Service Applications à Secure Store Service à Double Click it à Select your Secure Store Target Application à Double Click on it à It will open edit screens à Navigate to next screen and then next again à On final page you would see two groups à One for Secure Store Target Application Administrators (The people in this group would be able to modify the Secure Store Target Application settings, if they have permission for Central Administration site.), the other for Secure Store Target Application Members, this is the group we should add our target users/group on SharePoint that we want to provide access to external data.


Please refer attached screens.
The first screen shows how to set permission on "Business Data Connectivity Service".

The Second screen shows how to set permission on "Secure Store Service"



Tuesday 24 November 2015

When you create a site in SharePoint using its "Save Site As Template" functionality, NO data in Web designer Galleries --> Composed Looks library.

Problem: 


When you create a site from Save Site As Template functionality either using Visual Studio to modify the wsp or directly creating a site from the Template. You don’t see any data in Web designer Galleries à Composed Looks library. Normally this library should have data similar to following:


Whereas you see similar to following when a site was created using "Save Site as template" WSP.




Reason: When you create a Site using the wsp that was created by "Save Site as Template" functionality, it changes a XsltListViewWebPart to ListViewWebPart in _layout\design\AllItems.aspx page.


Solution: To replace ListViewWebPart by XsltListViewWebPart.

Following picture is showing correct content of AllItems.aspx page (taken from a working site that displays correctly data in Web designer Galleriesà Composed Looks).



Whereas following pictures shows incorrect ListViewWebPart is placed in AllItems.aspx (taken from a non working site that displays no data in Web designer Galleriesà Composed Looks.)


To fix the issue please follow following steps:

Step 1: Open the WebSite that shows correct data in a SharePoint Designer instance. Navigate to All Filesà _catalogàdesignàAllItems.aspx page and open the file.

Step 2: Copy the section that has WebPartPages:XsltListViewWebPart  to a Notepad file lets name it Target.txt. We will use this to create our own WebPartPages:XsltListViewWebPart tag and will finally replace that to the AllItems.aspx page of the site that is not working.



Step 3: Now open our site that has problem, using SharePoint Designer. Navigate to All Filesà _catalogàdesignàAllItems.aspx Page and create a copy of this page so that if something goes wrong then you can always restore it.

Step 4. Checkout the AllItems.aspx page. Locate the WebPartPages:ListViewWebPart tag. Copy the whole tag to notepad file, lets name it Source.txt.

Step 5. We will use data (only some Guids) from Source.txt and will replace those Guids at correct places in Target.txt. Finally we will have our tag ready to be replaced in problematic AllItems.aspx file. Please refer following picture for data that has to be replaced in Target.txt from Source.txt.

Step 6. You will have to replace 1, 4, and 6 with View Name value from Source.txt.
Step 7: You will have to replace 2 with ListName from Source.txt.
Step 8: You will have to replace 3 with ListId from Source.txt.
Step 9: Finally your content in Target.txt are changed something similar to the following:
Step 10: Now replace the content of Target.txt into WebPartPages:ListViewWebPart tag in AllItems.aspx of the site that is not displaying Composed Looks data.
Step 11: Save and check in the file and try browsing content of Composed Looks and you should see your data.


Thursday 19 November 2015

Error occurred in deployment step 'Add Solution': The XSN cannot be used on the server.

This morning I had an issue while deploying an InfoPath 2013 form to a SharePoint Server using Visual Studio 2015 feature framework. The weird error message was as follows:

"Error occurred in deployment step 'Add Solution': The XSN cannot be used on the server."

After playing with InfoPath Designer's publishing options it turned out to be a very simple problem.

You have to publish the form to network location, with domain level security and Access Path should be blank. I have posted a few picture to explain where would you have an option to leave "Access Path" as Blank.









Thursday 8 October 2015

How to force an Update to SharePoint Solution Packages (WSP) in Visual Studio 2015 without using "Deploy" option

Recently I had hard time to figure out that why my features are not getting upgraded using Update-SPSolution Power-shell script.

It turned out a very silly behavior of Visual Studio 2015. Whenever you build/rebuild your solution it doesn't update WSP file. However if you want to redeploy your solution then Visual Studio's "Deploy" option force an update on WSP file. Since I am performing an upgrade on my features "Re - Deploy" was not an option.

After finding this behavior initially I thought of using Ms-build to create a wsp file and get the work done and this is what people normally do. But somewhere in my mind I was puzzled what if I have to use Visual Studio for this? Turn out to be very simple option. You can use "Publish" your solution to file system. It forces a new build and proper update of artifacts within WSP.


Thursday 6 August 2015

How to change column names and column orders in one or more lists but not to all lists that are based upon a Site Content Type.


If you have a Site content type and if there are more than one lists that are using it. Sometimes you might have requirement to change column names and column order only in one or more lists but not all. If you make these changes to Site Content Type then it will affect all. You can try doing it at List Content Type level rather than at Site Content Type level. It is fully supported. You can make some interesting local changes that are applicable to one or more list but not to all. For example you can delete some columns in the list content type for one or more lists or you can change column order etc. 

Tuesday 21 July 2015

Stay tuned for an end to end solution using mostly OOTB or Client side technology to provision a fully function SharePoint 2007

Stay tuned for an end to end solution using mostly OOTB or Client side technology to provision a fully function SharePoint 2007 (I know my client is still using MOSS :() Site using Site Template that provides a real life Business Processes automation and leverage InfoPath Forms to adjust its data sources depending upon the place it is being loaded and multiple data sources using various SharePoint artifacts and many more :)

Thursday 16 July 2015

SharePoint 2010: An end to end Solution using Content Based Routing

Problem:  SuYo Corporation buys raw materials from its suppliers. It receives Invoices from the Suppliers. Account department keep them in separate locations department wise. However this is posing a challenge because all invoices are not stored at one place and often it’s very difficult to maintain them. IT team has identified this issue and now they want to design a solution that will allow them:
  • To collect some Meta data while uploading the Invoices in SharePoint Document Libraries.
  • To provide a functionality that will allow end user to move an Invoice from a Document Library to a Centralized Location and only a link will be left to that Document Library.
  • To have retention policy applied that will delete an invoice after 2 years automatically.
Following will demonstrate a few out of the box functionality of SharePoint 2010.
  1. How to create a Web Application, Site Collection, Site and document library.
  2. How to use Host Header and to configure host in DNS to mimic a real world scenario.
  3. How to create a custom Content Type.
  4. How to define an Expiration and retention policy and associate it with the Custom Content Type.
  5. How to Setup Send To locations and define Content Routing Rules in SharePoint 2010.
Solution: Let’s use out of the box features to accomplish the job. It’s a little long exercise but very easy. I am outlining all steps as following to summarize the solution.
  • Create a Web Application and provide a Host Header.
  • Map Host Header URL to DNS.
  • Define a custom Content Type (For this example we are creating “Invoice” content type.) and its Expiration and retention policy.
  • Create a Team Site and a Document Library.
  • Associate the document library with the Content Type (“Invoice”).
  • Create a target Site based upon “Document Center” template and create a Document Library associate it with the “Invoice” Content Type. Note: Target Site could be based upon any template. It’s the Content Organizer feature that enable content organizing functionality.
  • Activate Content Organizer Feature on the Target Site.
  • Get the Web Service URL from the Target Site
  • Configure Drop Off/Send to Location in SharePoint Central Administration using web service URL.
  • Define the Routing Rules for “Invoice” Content Type in Target Site.

Create a Web Application as follows:
  1. Open SharePoint 2010 Central Administration, click on Manage Web Application under Application Management node.
  2. Click on “New” to create a new Web Application
  3. Create a new Web Application with the attributes as shown below. Let’s provide a value for Host Header attribute so that it’s more similar to real time world. In real world one normally prefers to use something like http://suyu.sscontoso.com rather than http://machinename/abc. For this example let’s provide http://suyu.sscontoso.com for Host Header. Note: Since we are defining an URL for Host Header then we will have to make sure when user type in this URL in the Browser then this should get resolve correctly and request is routed to the intended web application. To accomplish this we will have to register this URL to DNS. Let’s use a meaningful name for Application pool and database. This is very handy to get an idea by seeing name which database or application pool is associated with the web application. Other attributes are left with default values. Now click on OK button to create the new Web Application.
  4. Next screen is to create a Site Collection. Site Collection is a logical container that contains a Root Site and a number of Sites underneath. 
  5. Now before creating a Site Collection let’s register the Host Header Entry into DNS as following. Once it’s done then we will return to Step 4 to create the Site Collection.
    1. Register the Host Header in DNS. Notice that I intent to use suyucorp.sscontoso.com URL.
    2. Open DNS Manager by clicking on DNS under Administrative Tools (In this example we are using Windows Server 2008 R2).
  6. Expand “Forward Lookup Zones” and right click on your domain name. In my case its sscontoso.com and then click on New Host (A or AAAA).
  7. Provide inputs as following and click on Add Host. Notice how fully qualified domain name (FQDN) is getting constructed. In order to resolve requests correctly URL in FQDN box should match to what we have provided while creating the web application. Click on “Add Host”.
  8. Now let’s go back to the Step where we were trying to create site collection (Step 4). Click on “Create Site Collection” to create a new Site Collection. In the following Screen, provide meaningful Title, template and a user name who will be acting as Primary Site Collection Administrator. Click on OK to create the site collection.
  9. We should see Site Collection Created Successfully message. 
  10. Click on the URL to view your site collection.
  11. Now let’s create a custom content type for “Invoice”. What is a Content Type? In layman’s term then its Meta Data (Data about data) and behaviour for Content Items. It is independent from the type of documents. In our context an Invoice can be a word document or PDF document or Excel document but same Content Type can be applied to either of them. So next question could be what should be captured from a given content (in our context, invoice) that define Content Type? This entirely dependent upon specific requirement however one should think about the attributes that could help in describing and organizing contents. So let’s try to understand what could be Content Type for an Invoice by following example.
    1. SuYo Corp receives invoices from their suppliers. In order to file them properly Accountant put them in a file (Physical file). After a year there could be hundreds of Invoices copies in that file and one may find it very difficult to maintain. If you are an intelligent content manager then you would try to label the contents within the folder so that you can find a particular invoice quickly and next time when a new invoice is received then it can be placed accordingly. So in above example “Label” could be a Meta data for the invoice. We can use a content type to group a related set of attribute to define the content.
    2. In Our case we will keep it very simple and we are going to define Content Type using two attributes 1. Manager Name and 2. Department.
    3. Once we decided the information/columns that we are going to collect, then we will have to decide how the data would be populated. In our example we decide to collect Manager Name and Department. We could have an option to auto populate this information from the document itself. Here for simplicity we will ask information worker to provide this information at the time of uploading invoice in the document library.
  12. Click on Site Action and then Click on “Site Settings”.
  13. Under Galleries click on “Site Content Type”.
  14. Then Click on “Create” button.
  15. Provide a name, description, select parent content type and group. Let’s select Document content type that will act as base type for our invoice content type. Let’s put this into a new Group. Then click OK.


  16. You will be displaying following Screen. Let’s add two columns 1. Manager Name and 2. Department Name. Click on “Add from new Site Columns”.
  17. Provide Column Name value “Manager Name”, Select “Single Line of Text” and select “New Group” under Group and provide Group Name (“SuYoCorp Columns”) as following. Leave other values as default and then click OK.
  18. Repeat Step 17 to create Department Name site column. Provide Column Name as “Department Name”, Select “Choice” in “The Type of Information in this column is:”, select already created group (in our case it is “SuYoCorp Columns”) in “Existing Group” under Group and provide name of the departments in “Additional Column Settings” (Lets provide three choices Sales, Purchase and Quality.). Leave remaining as default and then Click OK.
  19. Now our Invoice Content Type should look like following. By now we have successfully defined a content type.
  20. Let’s define a Retention Policy to this Content Type. Click on “Information Management Policy Settings”. Click on “Enable Retention” check box to select it. You will be displayed “Add a retention stage...” link just below this check box. Click on “Add a retention stage...” link, it will display a screen as shown below. 
  21. Select “Created” in Time Period and type “2” in adjacent text box and select “Years”. In Action section select “Permanent Delete” in “When this stage is triggered, perform following action:” drop down. Basically we are defining here a retention policy that deletes an invoice once it reaches the term defined. Notice we are defining this policy on a Content Type so in other words it will be applicable everywhere in the given scope and we don’t need to define it locally. However it entirely depends upon the requirement. Click on OK button on “Stage Properties” screen then click OK again on “Edit Policy” Screen.
  22. Next step is to define “Send To” Location in “SharePoint Central Administration”. Once we complete this step then it will allow us to send a document to a centralized place by selecting the document and using “Send to...” option in ECB menu. In order to do this we have to create a Source Document Library and Target Document Library. Let’s create a site named as “Sales” to host a source document Library and then we will create a target site (It could be any site but for this example we will create a document center site and a target Document library).
    1. Browse http://suyucorp.sscontoso.com and click on “Site Actions” and then click on “New Site”. Then Select “Team Site” template type, provide site name “Sales” and type in “sales” for URL as shown below. Click on “Create” button.



    2. Now create one source document library named “Sales Documents”. Click on “Libraries” on the left hand side Quick Launch section then click on “Create” link on the top left hand side. Then select “Document Library” type and provide name “Sales Document” then click on “Create” button.
    3. Now let’s associate the Invoice Content Type with this document library. Click on “Library Settings” that is on Right Side of Top Menu.
    4. Then click on “Advance Settings”
    5. Then select “Yes” for “Allow Management of Content Types” as shown below. Then click on “OK” button.
    6. After you click on OK button it will take you back to the Library Settings page again and there will be an option “Add from existing content types” link will be available under Content Types section. Click on this link. It will bring “Add content types” page. Select “SuYoCorp Contents” from “Select Site Content type from:” drop down and then select “Invoice” Content type from “Available Site Content Types” then click on “Add>” button and then click on “OK” button.
    7. Now you will notice that Invoice content type is added to your document library as shown below.
    8. Now under Content Types click on “Document” and then click on “Delete this content type” on the following screen as shown below. So actually we are removing generic “Document” content type association from this library. In other words we will have only Invoice content type associated with this library. Click on “On” to confirm the deletion.
    9. After associating Invoice content type you can create a new document based upon your content type. This is one approach to make sure that you specific set of document libraries that may contains documents adhere to the content types. See below image. You have Invoice template available in “New” button.
    10. Now let’s add at least one invoice. To do so, click on “Add Document” link then browse to already existing Invoice then click on “Ok” button to add this to the “Sales Document” library.
    11. In following screen you will notice that columns defined within the Invoice content types are available here. This is the way we can seek some additional Meta data information from the user who is uploading the document in the library. Provide some Meta data and select “Sales” as department name then click on “Save” to add this invoice to the document library.
    12. Hover your mouse on the document and click on “Send To” link from the ECB menu as shown below.
    13. Our aim is to send this document to a central location and should appear on above shown ECB menu under “Send To” option. Here you can see that we don’t have this. To do so let’s create first a target site and then we will create a Document Library (Let’s say its name is “SuYu Invoice Library”) to store all Invoices from different libraries. Let’s create a site under http://suyucorp.sscontoso.com:3333. Type http://suyucorp.sscontoso.com:3333 and then click on “Site Action” then “New Site” to create a new Site.
    14. On Create screen, provide name as “SuYu Documents”and in URL provide “suyudocs” then click on “Create” button as shown below.
    15. You will be presented welcome screen as shown below.
    16. Create a new Document Library named “SuYu Invoice Library” as shown below.
    17. Once Library is created then click on “Library Settings” button. Then click on “Advance Settings” and then click on “yes” under “Allow Management of Content types” and then click “OK” as shown below.
    18. Click on “Add from existing Content Types” and then associate Invoice content type as we did before.
    19. Now click on “Document” under “Content Types” and then click on “Delete this content type”.
    20. Click on “Site Settings” under “Site Actions”. Then on following screen click on “Manage Site Features” under “Site Actions”. It will display following screen. Then activate “Content Organizer” feature by clicking on “Activate” button next to it. This will add two additional links in “Site Administration” section on “Site Settings” page.
    21. Click on “Content Organizer Rule” link in “Site Administration” section. This will open following page. Click on “Add new item”. Select “SuyoCorp Contents” group, “Invoice” content type and chose “Target Location”. In our case I selected the “Suyu Invoice Library” as Target Location. Click on “Ok” button. Now we have set up a Routing rule to our document center site.
    22. Now click on “Content Organizer Settings” link under “Site Administration” section on “Site Settings” as shown below. Here we will copy web service URL that will be used to configure “Send To connections” in Central Administration.
    23. Select and copy web service URL from “Submission Points”. I have highlighted this on above screen.
    24. Now we have a Target Site and a Target Document Library. Let’s configure this path to Central Administration so that it will be available on Web Application level. Open SharePoint 2010 Central Administration. Under General Application Setting section click on “Configure Send to connections” link.
    25. It will open “Configure Send to Connection” screen. Select your web application and then provide a name, web service URL (that copied in 22.23 step) and select “Move and leave a link” in “Send to action”. Click on “Add Connection” to add this connection.
    26. Now everything is done and you are ready to give it a try.
    27. Go to your “Sales Document” library in “Sales” site. Select an Invoice by checking the check box adjacent to it. Then hover the mouse on the selected invoice to bring ECB menu. Once ECB menu is available then click on “Send To”. You will notice that a new entry “SuyuCorp Document Center” is available. If you click on this option and confirm on next message then your document will be moved to the Document Center and routing rule will be evaluated to save it to “Suyu Documents” library. A confirmation message will be displayed when your document is moved. Your source library will have a link to the document.
    28. You might have already figured it out that this routing is based upon the Content Type. Let’s say if I try to send a document to document center that is not of “Invoice” content type, then where will that document go? Document Center has a “Drop Off Library”. When a document is send to document center then content routing rules are evaluated and if there is no rule available then that document stays in this library.