Monday, 9 June 2014

Configuring Search in SharePoint Server 2013



Configuring Search in SharePoint Server 2013 is not a simple task. There are some critical options that need to be taken care of while configuring. Most of them are illustrated below:

From the Central Admin Home page click Manage service applications under Application Management…



In the Ribbon click New and select Search Service Application.



Name your Search Service Application and Select a service account





Next you’ll select or create an application pool for search.  I’m just going to run on a existing app pool to conserve resources.  If this were production I’d likely create a new app pool for both the search admin web service and the search query and site settings web service.






Click OK and wait…




Upon completion you’ll be presented with the following:





Note: the second time I configured the service app I accessed Central Admin from a computer that wasn’t part of the farm and it appeared to get hung up.  I then browsed to the service applications screen, search showed up just as it does below and everything works as it should.





Now we shall focus on Content Sources. On the Search Administration page there are several links broken into titled categories.  The second group is titled Crawling.


“A content source is a set of options that you use to specify what, when and how to crawl.”

When Search is initially configured the content source “Local SharePoint sites” is created, and as the name implies this includes all SharePoint sites in your farm.  As you create additional web apps they are automatically added to this content source.  Another thing to note is that changing your default AAM will result in that URL being added to your content source in addition to whatever the original URL of your site was, so there may be need for cleanup. 

This is also good to know

“Changing a content source requires a full crawl for that content source”

To read more about add, edit or delete content sources in SharePoint Server 2013


Clicking on Content Sources will bring you to the Manage Content Sources page…


Clicking on the dropdown will result in the following menu appearing…



  
Clicking Edit or on the Name will bring you to the edit content source page.






From this page your initial options are to name your content source, view content source details and add or remove start addresses.  Keep in mind that the Edit and Add pages are basically the same.  Obviously, you are going to need to click the New Content Source button to get to the Add Content Source page etc…   A start address is the point from which the crawler will begin to crawl your site.  Typically Local SharePoint sites is going to have all of your web apps listed by default.
Crawl Settings really only applies to when you are creating a content source because once you have selected a setting you can’t change it.  When creating a content source you have the following options.




Switching between the first 4 of these really just changes the path requirement, as illustrated in the screen shot below.



However, Line of Business data and Custom Repository require significantly different information…  Line of Business Data requires you to select a BCS Service application which of course requires that you have BCS provisioned and a Service Application is connected to some LOB System. 
More information on both source types can be found here…

And here…






A Custom Repository requires that you have a Custom Connector registered.




Your only edit options are,

“Crawl everything under the hostname for each start address”

Or

“Only crawl the Site Collection of each start address”. 


The second option would be used if you want to crawl some site collections in a web app less or more often than others.  There are several factors that would go into a decision like this.  For instance, varying content change frequency between site collections.

The next section deals with Crawl Schedules.  Crawl Schedules has the new option, Enable Continuous Crawls.

“Enable continuous crawls is a crawl schedule option that is new in SharePoint 2013. It is available only for content sources that use the SharePoint sites content source type. A continuous crawl starts at set intervals. The default interval is 15 minutes, but you can set continuous crawls to occur at shorter intervals by using Windows PowerShell.”



The familiar Incremental Crawl and Full Crawl scheduling options are next.  Both of which allow you to create a schedule.    Crawl schedules require a good bit of planning and are very much dependent on the specific needs of the environment.

Last we have Content Source Priority.  Your options here are High and Normal.  The Crawl system uses this to prioritize crawling resources with High content sources being top priority.


From a Content Source’s drop down menu the View Crawl Log options is available.



Clicking on this will bring you to the crawl log 
.


This screen provides you with Average Crawl Duration and Summary information.  This is where you go asses the health of your content source crawls, and is going to be your first stop when you need to troubleshoot content source issues.

Clicking on the number of errors will bring you to this page…



You will be taken to this same page, filtered appropriately, if you click on Warnings or Successes.  URL View allows you to search for crawled documents.  Databases provides a list of your crawl store databases and the number of items in each.  For more information I suggest reading this TechNet article…




Monday, 12 May 2014

SharePoint 2013 Development: Solutions vs. Apps

From  Denis Stetsenko's  Blog----Posted on 

SharePoint Solutions and Apps image

SharePoint 2013, like all recent versions of SharePoint, is a great development platform that allows customizations via supported extensibility models. There are two ways to add custom functionality to SharePoint 2013: SharePoint Solutions and SharePoint Apps. At a high-level, we will cover each extensibility model, along with advantages and disadvantages of each approach from the development and deployment perspectives.
Overview of SharePoint Solutions (*.wsp)
SharePoint 2013 will support this classic model well-known to all SharePoint developers. SharePoint Solutions are still considered a good option, and in some cases the only option, for customizing SharePoint.
SharePoint Solutions can be developed using Visual Studio 2012, which includes a number of supported templates. They can integrate with external applications using Business Connectivity Services (BCS), Web Services, or a custom Service Application.
There are two types of SharePoint Solutions: Farm Solutions and Sandboxed Solutions.
Farm Solutions, first introduced in MOSS 2007, are fully-trusted and have access to the full server-side SharePoint API. They must be deployed by a Farm Administrator and run in the main SharePoint worker process. Customizations added via Farm Solutions are available to the entire farm, which makes them a great choice for a wide array of custom features, such as branding solutions and administration tools. SharePoint Solutions can also be scoped to individual Web Applications, Site Collections, and Sites.
Sandboxed Solutions, first introduced in SharePoint 2010, are partially trusted, and can only access a subset of the server-side SharePoint API. Another limitation is that they cannot make any calls to externally-hosted Web Services or databases, which can still be achieved using client-side technologies. Sandboxed Solutions can be deployed (uploaded) by a Site Collection Owner or Administrator via a browser and run in the SharePoint sandbox worker process. Customizations added via Sandboxed Solutions are available to the entire Site Collection, to which they are deployed, making them a great choice for an array of features, such as custom workflows or site/list/library templates. Even though Sandboxed Solutions are still allowed in SharePoint 2013, they are deprecated and should be avoided in favor of SharePoint Apps.
Introducing SharePoint Apps (*.app)
This is a brand new extensibility model introduced in SharePoint 2013 that addresses some of the inherent challenges with SharePoint Solutions. The biggest difference between apps and solutions is that apps run completely outside of the SharePoint server, meaning their custom code is executed either in the context of the client browser or on other servers not running SharePoint (i.e., any Web server hosted on premise or in the Cloud). Therefore, this model provides the highest level of app isolation. However, as a result, apps cannot natively interact with other apps. SharePoint Apps are generally scoped to individual Sites or a special Site called the App Catalog, which allows for other Sites to connect and consume the app.
SharePoint Apps can be developed using Visual Studio 2012, which includes a fully supported app template. They can also be developed using “NAPA” Office 365 Development Tools, a new set of tools for developing apps in a Web browser only available in hosted installations. SharePoint Apps can leverage any of the industry Web standards such as HTML5 and CSS3, JavaScript and jQuery (or any other frameworks/libraries), JSON, REST, OData, and OAuth. Thus, the options for integrating with external applications are vast.
There are three types of SharePoint Apps: SharePoint-Hosted Apps, Provider-Hosted Apps, and Azure Auto-Hosted Apps.
SharePoint-Hosted Apps are manifested entirely within SharePoint server and generally have no external dependencies. Their custom code is implemented by leveraging Client-Side Object Model (CSOM) or REST API, and is executed within the context of a browser. SharePoint-Hosted Apps can access libraries and lists to store content. Examples of these kinds of apps are PTO request or expense calculator.
Provider-Hosted Apps may have SharePoint components, similar to SharePoint-Hosted Apps, but the main business logic and data storage are manifested in an external infrastructure, such as an external Web server or in the Cloud. These apps are ideal for integration with external systems, such as a help desk support system. It’s important to note that Provider-Hosted Apps can also be developed using any other non-Microsoft tools and technologies, such as Eclipse or LAMP, due to the fact that their business logic and data storage are provisioned by the external infrastructure.
Azure Auto-Hosted Apps are somewhat similar to the Provider-Hosted Apps in that their main business logic and data storage are manifested in an external infrastructure. However, the Azure Auto-Hosted App package additionally contains the Website and database that is deployed and run outside of SharePoint. When this type of app is installed, SharePoint handles automatic provisioning of the Azure SQL Database and Azure-Hosted Website in an existing Azure account setup in the farm.
Development Considerations
SharePoint Solutions have inherent issues that stem from their complexity and that they run directly on the SharePoint server. Farm Solutions are the root cause of most SharePoint outages and errors; they are cumbersome to deploy and not suitable for hosted environments. Sandboxed Solutions have access to limited server-side API, but still require knowledge and experience with the server-side API. In addition, SharePoint Solutions are costly to develop and require performance monitoring to ensure they don’t affect the farm performance.
SharePoint Apps are now the preferred method for developing SharePoint customizations. They have the following advantages over SharePoint Solutions:

  • Stability: Since SharePoint Apps never run on the SharePoint server, this greatly increases the stability and performance of the farm. It makes it easier to upgrade to the next version of SharePoint since testing platform independent Apps is easier and faster than testing Solutions.

  •  Capability: SharePoint Apps can communicate with SharePoint via OData and CSOM. Microsoft has greatly improved the capabilities of the CSOM and the REST API to enable developers to create a wide-range of custom solutions without using the server-side API.
  •   Security: SharePoint Apps can leverage the newly added support for OAuth 2.0, which provides an easy way to manage their permissions. Developers can specify which permissions the app needs in order to function. The end-user installing the app is then prompted to accept the permission request the app needs to function.

  • Reusability: Apps can be packaged, reused, and sold via a Corporate or Public Marketplace, which makes it easy for end-users to acquire new apps. Also, the same exact app is guaranteed to work in both on-premise and Cloud environments.

  •  Deployability: Microsoft has made great investments in simplifying the app installation and upgrade processes; thus, addressing many developer challenges with the solution model.
What Should I Use?
SharePoint Apps are capable enough to replace most of the Farm and Sandboxed Solutions. Specifically, they are suitable for a wide range of customizations, including:

  •         Custom Web Parts
  •        Event and Feature Receivers
  •        Custom Field Types
  •        Application Pages
However, there are some SharePoint components which do not have an equivalent in the SharePoint App Model. Some types of customizations are only suitable for Farm Solutions, including:

  •        Custom Site Definitions
  •         Delegate Controls
  •         Custom Themes
  •          Custom action groups and custom action hiding
  •          User Controls
For more information on how to choose SharePoint Solutions or Apps, check out the article on “Apps for SharePoint compared with SharePoint solutions.”
Deployment Considerations
SharePoint 2013 can be deployed in three different ways: On-Premise Installation, Office 365 & SharePoint Online, and Hosted Installation. Farm Solutions can only be deployed to the On-Premise Installation of SharePoint. Sandboxed Solutions and SharePoint Apps can be deployed to all three different types SharePoint installations.
Conclusion
SharePoint Farm and Sandboxed Solutions are still supported in SharePoint 2013, but Sandbox Solutions are deprecated and should not be used. In some cases, Farm Solutions are either a better way or the only way for specific types of customizations. SharePoint Apps provide a brand new approach to extend SharePoint functionality and are now the recommended way to develop customizations for SharePoint 2013. They address several development and deployment challenges commonly associated with SharePoint Solutions, and allow developers to leverage a wide range of modern Web standards and technologies.


Thursday, 8 May 2014

CAML Query on Multiple Look Up Value Field


It was undiscovered to me that what will be the value type of a multiple value look up field in a SharePoint list. To resolve this issue, I have created a SharePoint list in my local environment as shown in the figure below:


Then I created a look up type field in the newly created custom list as shown in the figure below:


With the list item is populated the list item looks like the screenshots below:


Then I have used CAML Query Designer to obtain the query and observed the Value Type of the multiple value look up field as shown in the below query:


So, the value type of the multiple value look up field is discovered now. And the value type is 'LookupMulti' .

That's it.  Happy SharePointing.




Sunday, 30 March 2014

COLOR CODE CALENDAR EVENTS IN SHAREPOINT


SharePoint calendars can be hard to read when all of the events are the same color. A simple no-code solution is to use multiple views. This blog post will describe the steps, in detail, of how to create a SharePoint 2013 calendar with multiple colors, for your viewing pleasure.
Create column
The first step is to create an additional column for your calendar. This column should be something you use to separate your events from one another. In this calendar I will use Conference Rooms. You might need a calendar to book your conference room usage in your company, but when you look at an overview of the calendar you cannot tell which room is being used without looking more into each event.

Color Code Calendar Events in SharePoint

On the top left of your calendar select CALENDAR and to the far right select List Settings.


Color Code Calendar Events in SharePoint
Scroll down a little and under Columns select Create Column.

Color Code Calendar Events in SharePoint
Enter in the name of your column and select Choice.

Color Code Calendar Events in SharePoint
Select the settings that you wish to apply to this column and type in each conference room name that you would like for this calendar. Select OK to create the column. Do not select Enforce unique values.

CREATE VIEWS

Next you will need to create a view for each conference room. These views will later be overlapped on one another. A view should be created for each conference room you would like to use.
Color Code Calendar Events in SharePoint

Create a View.

Color Code Calendar Events in SharePoint
Select Calendar View

Color Code Calendar Events in SharePoint

Type the conference room name as the view name.

Color Coded Calendar Events in SharePoint

Add a filter to the view. Select OK. Repeat the steps for each conference room. So I will now create a view for Lincoln Room, Pentagon Area, Summit 7 Building, and Area 51. The next step is to add the colors.
Overlap
Once all of your views are complete you will need to use the overlap function to create one view with multiple colors for each event. Once complete you should be able to select the drop-down for Current View and see all of your views.

Color Code Calendar Events in SharePoint

Under Default select Calendar. You will then proceed to add all of the views to the default view using Calendars Overlay.

Color Code Calendar Events in SharePoint
Select Calendars Overlay
Color Code Calendar Events in SharePoint
Add a New Calendar
Color Code Calendar Events in SharePoint

Type in the name of the conference room as the Calendar Name. Type in a description. Select a Color and Select Resolve to fill in the List and List View drop downs. Select the Calendar you have created all the views for as the List. Select the List View that is the same as the Calendar Name. This will need to be repeated for each conference room.

Color Code Calendar Events in SharePoint

Once complete you should see all of your conference rooms here as New Calendars. Select OK.
Filter
The last step is to filter out duplicate entries. When you create an event on your default calendar now one event will be created for the specific conference room you select and another event will be created on the default calendar because they are overlapped. To make sure duplicate events do not appear you will need to filter out all the events for the default calendar.

Color Code Calendar Events in SharePoint
Select Modify View
Color Code Calendar Events in SharePoint

Filter out all events that do not have a Conference room selected by leaving the equal to blank.
Add events
Go back to the default calendar view and start adding events. Select The Conference Room the event is being held in and save it. You will notice the event will not be color coded and your calendar should look similar to this after adding events.

Color Code Calendar Events in SharePoint

This method can be used with more than just conference rooms. Some examples would be a work schedule for specific people. You can create views and select a color for each person. You can use it for specific clients. The only downfall to this approach is the amount of colors available and the setup time it takes.
Hope you find this useful!

Monday, 24 March 2014

How to get Raw HTML from a Page : System.Net.WebResponse

Retrieving a page's HTML can sometimes be necessary in applications. You could be filling columns for actual meta data of sites or may retrieving remote web sites for specific content. It's require very simple code to do all the stuff

// pass the site URL
string strHTML = Strip(Request(strWebURL + "/" + file.Url, "GET"));

//The Request Function
String Request(String uri, String verb)       {

            WebRequest request = WebRequest.Create(uri);
            request.ContentType = "application/x-www-form-urlencoded";
            request.Method = verb;
            request.ContentLength = 0;
            WebResponse response = request.GetResponse();
            if (response == null)
            return null;
            StreamReader reader = new StreamReader(response.GetResponseStream());
            return reader.ReadToEnd().Trim();
        }

// The Strip function, to remove style, scripts & Html tags from the text

 public string Strip(string text)
        {
            text = Regex.Replace(text, "", "", RegexOptions.Singleline | RegexOptions.IgnoreCase);
            text = Regex.Replace(text, "", "", RegexOptions.Singleline | RegexOptions.IgnoreCase);
            text = Regex.Replace(text, @"<(.|\n)*?>", string.Empty);
            text = text.Replace("\r\n\t", " ").Replace("\n", " ").Replace("\r", " ").Replace("\t", " ");
            return text;
        }

// That's All

How to programmatically determine customized pages in a site in SharePoint 2013


What happens when the need is to determine programmatically that a given page has been customized/ghosted or not?

We can use the "vti_hasdefaultcontent" property of the "SPFile" class to determine whether a file is customized or native.

SPFile file = SPContext.Current.Web.RootFolder.Files["default.aspx"]; 

bool IsCustomized = (bool) file.Properties["vti_hasdefaultcontent"];

Friday, 21 March 2014

Programmatically create a folder in a document library and in a list

Programmatically create a folder in a document library


I was able to successfully create a folder in a document library using this code:

SPList list = web.Lists.TryGetList("ListTitle");
SPFolderCollection folderColl = list.RootFolder.SubFolders;
SPFolder newFolder = folderColl.Add(FolderUrl);

FolderUrl means one of the following:
  • "/Document Library/Folder1"
    Creates a folder named “Folder1” under “Document Library”…
  • "/Document Library/Folder1/Folder11"
    Creates a folder named “Folder11” under “Folder1” in “Document Library”…
  • "/Subsite/Document Library/Folder1"
    Creates a folder named “Folder1” under “Document Library” in a sub site…
  • "/Subsite/Document Library/Folder1/Folder11" 
    Creates a folder named “Folder11” under “Folder1” in “Document Library” in a sub site… 

Here is the desired result:



Programmatically create a folder in a list

So after we can create a folder in a SharePoint document library we now can create them in SharePoint lists.

I was able to successfully create a folder in a SharePoint list using this code :

SPList list = web.Lists.TryGetList("ListTitle");
SPListItem newFolderItem = list.Items.Add(completeFolderUrl, SPFileSystemObjectType.Folder);
newFolderItem["Title"] = "TitleOfTheFolder";
newFolderItem.Update();

completeFolderUrl means one of the following:
  • "/lists/Custom List"
    The folder is created under “Custom List”…
  • "/lists/Custom List/Folder1"
    The folder is created under “Folder1” in “Custom List”…
  • "/aboutus/lists/Custom List"
    The folder is created under “Custom List” in a sub site…
  • "/aboutus/lists/Custom List/Folder1"
    The folder is created under “Folder1” in “Custom List” in a sub site…
Important: The folder didn’t create for me when my “completeFolderUrl” ended with a slash ‘/’.

This is the desired result :