Friday, September 15, 2017

Custom Search in Masterpage (sharepoint)

1.Place following code in masterpage at the place of Search control

<div id="divtoload">

<input type="text" id="txtKeyword"/><input type="button" onClick="parent.location=searchfn()" style="width:30px !important; height:20px; background: url(/sites/dms/Style%20Library/Images/nd_magglasssearch.png)" />

</div>


2. place script on head tag of master page:
Here: site: "http://spserver:1234"

<script type="text/javascript">
function searchfn()
{
var ss = document.getElementById("txtKeyword").value;
if(ss =='')
{
alert('Plese enter search keyword');
return window.location;
}
else
{
var url = "http://spserver:1234/sites/search/results.aspx?k="
var url1 = url.concat(ss);
return url1;
}
}
</script>​

Configure Forms Based Authentication for SharePoint 2013

Part 1

Note: In 2013 you have the option to extend the existing web application to use for external users or you can use the same web application configured with both authentication (NTLM and Forms Based) methods. Difference will be if you are not extending web app, you and external users will use same URL to access the site.
After you create web application confirm by selecting the web app and click on Authentication Provider. By default all web apps created in 2013 are created using Claim Based Authentication.
In case  web app has windows authentication
Change authentication to claims based authentication as mentioned below
$cba = Get-SPWebApplication http://EnterYourSiteURL&#8221;
$cba.UseClaimsAuthentication = 1;
$cba.Update()
Now when you click on default it will take you to the screen where you can enable FBA for our partners or external users.
Remember Membership name and Role manager name mentioned here, it will be used later on in the providers in web.config.
After you hit save, web.config file for this web app will be updated with entry that confirm that forms based authentication is enabled. You can check by browsing the site, you should see a sign in page  at this stage as shown below.

Part 2

Let’s create data base to store external user information and password for authentication. There are many way to do that I will use this.
Open command prompt as administrator and initiate ASP.Net SQL Server Setup Wizard as mentioned below and click on next
At the next screen enter server name where SQL is running and you want to create data base
Enter the name of the data base. This will be the repository for all external users as shown below.
Click next to confirm the server name and database name and finish the process as shown below
At this point you can log in to your SQL and see your data base has been created there – well.
Since you are in SQL lets go and set up some permissions for this data base.
We need to set permissions for two accounts on this data base
  1. App Pool Account for Security TokenServiceApplication.
  2. App pool account for content web application
I am sure you know how to find the application pool account for both apps but just in case here is a screen shot from IIS.
Once you confirm your app pool account for both lets add them to newly created data base i.e. Partners (in this case)
Click on + sign next to Partners Database. Expand security, right click on Users, Click on New User. In new user wizard fill out app pool account identified above as shown below in the screen shot
Click on Membership and check all Role that start with asp.net and end with Full Access as shown below
Once Done, Click OK.
In my case I am working on dev machine and using same account for admin on machine and this account is also dbo on the data bases so it give me this message. If you get the same that means account already has the permissions for it, repeat the above steps for both account and let’s move to the next step.

Part 3

This is the step I wanted to write this blog for. I find some information on how to configure FBA in 2013 but this part was very confusing and not in detail in many posts. I will try to go in to details in an organized way as much as I can and if you think anything that can make it better to understand feel free to comment.
In order to configure forms based authentication with SQL database or ADAM / LDAP we need these 3 things. (this blog covers with SQL only)
  1. Connection String
  2. ASP.NET Membership Provider
  3. ASP.NET Role manager
Connection String:
Defines the connection properties and path to connect to database created above (Partners) for example data base server name, data base name. You can use this connection string and modify the server name and DB name highlighted in red as per your environment.
In add name tag you can give this connection string any name in this case I am using SqlConn. You can have more than one connection string in one environment so we use names to identify this.
<connectionStrings>
<add name=”SqlConn
connectionString=”server=ServerName;database=Partners; Integrated Security=true”/>
</connectionStrings>
Membership Provider:
Membership provider and Role provider define configuration for web app to connect to the asp.net data base. A connection string is defined to connect to the data base and based on member ship and role users get authentication for that web app.
Member ship also define policies and properties for passwords e.g. in the below member ship provider we have declare “minRequiredNonalphanumericCharacters=”1″” this mean you must have to have one non alpha numerical character in the password i.e. ! @, # etc. if you don’t want this password policy remove this line from the code.
For a full list of properties click here. Member ship provider is always declared with in <membership><providers> Tags.
You can use the mentioned below membership provider. Make sure name in red match with the names in your environment.
              <membership>
<providers>
<add name=”LDAPMembership
type=”System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”
connectionStringName=”SqlConn
enablePasswordRetrieval=”false”
enablePasswordReset=”true”
requiresQuestionAndAnswer=”false”
applicationName=”/”
requiresUniqueEmail=”true”
passwordFormat=”Hashed”
maxInvalidPasswordAttempts=”5″
minRequiredPasswordLength=”7″
minRequiredNonalphanumericCharacters=”1″
passwordAttemptWindow=”10″
passwordStrengthRegularExpression=”” />
</providers>
</membership>
Role Provider:
You can use role provider mentioned below. Just make sure names highlighted in red match your environment.
             <roleManager>
<providers>
<add name=”LDAPRole
connectionStringName=”SqlConn
applicationName=”/”
type=”System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” />
</providers>
</roleManager>

Now that you have all the pieces you need, let’s put them all in machine.config file. Why? In older version we use to edit web.config for central administration, SSP and content web app but you have to edit each web.config on each WFE to achieve this.
If you edit one file on each WFE i.e. machine .config it will take care of all web.config files mentioned above.
One more thing you will have to do is, edit web.config for Security Token service   Application and place this info in the web.config I will go in details of this also.
Let’s do it one by one.
For Machine.config file :
On WFE go to C:\Windows\Microsoft.Net\Framework64\v4.0.30319\Config
Take a backup of this file before you edit. Open machine.config file. You need to enter 3 things here
  1. Connection strings
  2. Membership provider
  3. Role manager
Below is screen shot of 2 sections from my Machine.config file before any changes
1-
2-
Easy way to do this is open machine.config file and search for Connection string and membership provider one by one and add your membership provider details as described earlier. After making changes your machine.config file will look as shown below
1
2-
Once done, save machine.config.
For Security TokenServiceApplication :
Open web.config for Security Token Service Application. Location for web.config can be find from IIS .
In IIS expand Sites, Expand SharePoint Web Services, Right click on Security Token Service Application and click on Explore. This will take you to folder where web.config file is. Take a backup of this file before you make any changes to it.
You need to enter 2 things here
  1. Membership provider
  2. Role Manager Provider
Below is screen shot of web.config before making any changes. Notice I scroll all the way down to get this screen shot.
If you don’t have System.web tag in this file you will have to create after </system.net>  as shown in the screen shot after modification below.
Once done save the file.
Configuration is complete now.
We have FBA set up but there are no users in the data base to test this work. Again there are many ways to do this e.g. using Visual studio but I will use SharePoint 2013 FBA Pack  available at CodePlex. Download the package from here and add, deploy solution in to your SharePoint farm. Once done you can find all the options in site settings page and step by step direction are also available here

Thursday, July 27, 2017

SharePoint 2013 branding MasterPage


Reference : http://blog.blksthl.com/2013/02/26/a-guide-to-quick-sharepoint-2013-branding/
NO DEVELOPMENT IN VISUAL STUDIO OR SHAREPOINT DESIGNER REQUIRED
------------------------------------------------------------------------------------------------------ This guide has been verified in SharePoint Foundation 2013 as well as Server and Online, BIG thanks to Chuck Snyder for verifying functionality in SharePoint Foundation 2013.Some of you may already have tried some of the branding features built into SharePoint 2013 and SharePointOnline (2013), Microsoft have added some functionality that makes it easier for some and harder for some. I had branding in 2010 pretty much figured out and now to me it seems like they have given the box a good shake, everything is almost in the same place as before…but not quite…
I have noticed that most of the branding info that is out, most blogs and presentations have been about branding a publishing site, meaning an external website or intranet portal or similar, sites meant to be branded and customized. In this guide I will fokus on the teamsite, probably the most used site of them all…
I will show you step by step how to access some of the basics in branding your sites, no development yet…the tools needed for this exercise, is notepad.exe…that’s it…
In this short guide, I will use a site located in SharePoint Online (2013/Preview, link at the end), but the steps are exactly the same in an onprem environment.
For the permanent production branding, I have to recommend using Visual Studio to create a wsp package, as long as you add the same files as I do here it will work the same. That way you will have an installable package that can be reinstalled and used in test and dev environment. You can also make sure the package works Before moving it into production.
We will make this:
Start4
Look like this:
after_v2
Now let’s get on with it:
Create a new site collection and work with the rootsite.
Start4
Having a brand-new unbranded, untouched team site, I will start by getting the files to start working with, we need a new MasterPage (.master) and a new StyleSheet (.css).
In the top right corner, click on the little cogwheel/gearwheel.
Settings1x
Then click on ‘Site settings’ in the dropdown.
Settings11x
Site Settings offers a lot of choices, we are only going to be using a few.
Settings2
The branding features of SharePoint are mainly located in the ‘Web Designer Galleries’ and the ‘Look and Feel’ sections of site settings.
Settings3
Settings4x
In Web Designer Galleries section, click on Master pages
Masterpage1
In here we will store the files we need, to make it a bit more structured, we will create a dedicated folder for our efforts only, I’ll call mine TrueSec.
In the ribbon section, click on the tab called FILES, then ‘New Folder’.
Masterpage2x
Type in the name and hit ‘Save’
Masterpage6x
The folders and files are in alphabetical order, so in my case using truesec, I have to go to the next page. Use the arrow at the bottom.
Masterpage21x
Masterpage7x
Ok, now we have a place to put our files, next, we download a copy of the default masterpage beeing used in a SharePoint 2013 team site, ‘Seattle.master’
Masterpage71x
Use the dropdown menu on the file
Seattlex
In the IE download bar, select the dropdown arrow and select ‘Save as’.
Seattle2x
Save the file in a suitable location, I put mine in a folder on the desktop. Leave the filename as is.
Seattle3x
Select ‘Open folder’
Seattle4x
Seattle5x
Next, we make a copy of the seattle.master and rename it to what we want. I’m going with truesec.master
Seattle6x
Seattle7x
Ok, now we have a local copy of the default masterpage called truesec.master. It is at this point still identical to the default and we’ll leave it that way for now.
Now, we get a copy of the default stylesheet used in the seattle.master, called core15.css.
Go back to the browser with your site and masterpage gallery, click on the SharePoint logo.
Masterpage1homex
Now, we are back in the root team site and its homepage, from here it is a simple task to download the stylesheet, since it is not located in the masterpage gallery, I’ll use a different method to get it.
In your Internet Explorer browser, click on F12, this will bring up the F12-Developer toolbar, a great built in tool.
StyleSheet2x
Click on the tab named ‘CSS’
StyleSheet3x
Make sure that the path is selected, that points to the core15.css file
StyleSheet8x
Then on the little ‘Save’ button
StyleSheet31x
This method may result in a slightly ‘off’ css file (missing navigation in one occation), the reason is that the developer dashbord will save a rendered css file instead of the actual file.
In order to avoid any risk for that, type in the full path to the actual corev15.css file, then save it to disk.
Place the file in the same folder locally on your computer as the seattle.master/truesec.master.
StyleSheet5x
Same as before, make a copy and then rename it to truesec.css
A slightly more difficult but better way, is to create a new blank text file and rename it to ‘truesec.css’, then, add to this file only the ID’s and Classes that you want to style.
Adding only the classes/ID’s you want to edit the styles for, will save bandwidth and improve performance as well as keep the css file manageble.
Example, say that you want to style the Page Title with a new font-size and color, add only this to the empty text file:
.ms-core-pageTitle
{
font-size:30pt;
color:rgb(255, 127, 39); /* blksthl orange */
}
(read the core15.css to get an idea of how it is built)
StyleSheet6x
StyleSheet7x
Ok, now we have both the files needed to make the changes to the branding, but we do need two more things to make the branding a bit more interesting. Logos, I’ll show you how to replace the default logo (the big one) and the favicon (the smaller ones), the little thing in the address bar that is actually used for a few things and will affect the braded feel of the site pretty much.
logo1x
I’m adding the files to my local folder to make it simple and keep it all in one place.
If you don’t already have a favicon for your organization, you can use any one of the free image to favicon sites available to create one from a image. I have used several and for example this works:http://favicon.htmlkit.com/favicon/.
This tool will also let you select the formats you want.
Logos1x
I have in my example a favicon file of dimension 32×32 with a color depth of 32. 16×16 works just as well.
Logos2
The original ‘SharePoint‘ logo is 180×64 and as long as you stay close to that, the design will be ok.
Logos3
Now, we will edit the files and add the simple magic lines….
First, we want to load out custom StyleSheet, it’s not custom yet, but loading it will allow you to make modifications to it later. So, open up the copy of the master file, in my case the file named truesec.master
(Notice the filepaths, all pointing to the masterpage gallery catalog and our truesec folder)
Attention! If you copy and paste from the code below, you may have to replace the quotes and double-quotes with your own, do a replace in notepad. I have tried to replace them in the code samples but be aware.
The quotes if copied here is for some reason of a different format and will cause the code to fail if used as-is. Usually you will see that you get a left and right version of the quotes, they do not work. See example:
quotesx
(This may differ depending on what text editor you are using)
Locate the line:
(Use Notepad find and search for ‘corev15’)<SharePoint:CssRegistration Name=”Themable/corev15.css” runat=”server”/>
custommaster1x
Add directly below it as one line:
<SharePoint:CssRegistration name=”/_catalogs/masterpage/truesec/truesec.css” After=”corev15.css” runat=”server”/>
That will make:
custommaster2x
Next we add our custom favicon, locate the line:
(Use Notepad find and search for ‘favicon’)<SharePoint:SPShortcutIcon runat=”server” IconUrl=”/_layouts/15/images/favicon.ico?rev=23″ />
Change it to:
<SharePoint:SPShortcutIcon runat=”server” IconUrl=”/_catalogs/masterpage/truesec/favicon.ico” />
custommaster5x
Next and last, we add the actual logo, locate the line below:
(Use Notepad find and search for ‘LogoImage’)
<SharePoint:SiteLogoImage CssClass=”ms-siteicon-img” name=”onetidHeadbnnr0″ id=”onetidHeadbnnr2″ LogoImageUrl=”/_layouts/15/images/siteIcon.png?rev=23″ runat=”server”/>
Edit or replace it to look like this:
<SharePoint:SiteLogoImage CssClass=”ms-siteicon-img” name=”onetidHeadbnnr0″ id=”onetidHeadbnnr2″ LogoImageUrl=”/_catalogs/masterpage/truesec/trueseclogo.png” runat=”server”/>
Update: Added missing endtag /> )

custommaster4x
There, the files are edited and if we upload and use these, we will have the logo and the favicon used in our site. We will at this point not touch the css.
Warning! Make sure that you do not make any mistakes editing the masterpage, if you accidentally remove something you could end up with a site that is inaccessible, if you do, SharePoint designer can be used to correct the masterpage again
(If you don’t plan to edit the css in the future, you can either skip loading it or at least clear the file of content, making it empty and quick to load.)
Upload the files in your local folder from the masterpage gallery, cogwheel, ‘Site settings’, ‘Master pages’. Browse to your folder, my ‘truesec’ folder.
Addfilesx
In the upload dialog, browse to your files, add a comment if you like but make sure that the destination folder points to your folder (relative path).
Addfiles1x
In the second dialog, make sure that you for the masterpage, select ASP.NET Master Page, like in the picture below, for the other files including the css, select Content type ‘Design file’
Addfiles61x
Ok, files uploaded, all ready to use…almost.
I have found that the master needs to be published as a major version before being accessible from the gui. Click on the dropdown arrow, then ‘Publish a Major Version’.
Apparently, if the publishing site feature hasn’t been activated, the ‘Publish as a Major Version’ is missing, the workaround then is to check the file out, then check it back in and select major version.
Addfiles7x
Now, we need to change the masterpage that is used…this is actually a part of the publishing features, but if you don’t have the site collection publishing feature and the site publishing feature activated, try using this direct link instead:
[URL to your team site]/_layouts/15/ChangeSiteMasterPage.aspx
The ’Site Setting – Site Master Page Setting’ dialog seems to only be available if the site Collection feature, ‘SharePoint Server Publishing Feature’, has once been enabled. Try it, I enabled it, accessed the page, then disabled it again and I could still access it. (I don’t Think that is by design.)
Sometimes there is an error when clicking ok but the masterpage was still updated…this in onprem as well as online.
For me it looks like:
path
Now, we change the masterpage used from this:
ChangeMaster1x
To this:
ChangeMaster2x
Click on OK in the bottom right corner.
ChangeMaster3x
Done, TADA!
Tadax
(The green background comes from Windows 8s adaptive coloring based on the background image, my background Changes on a Schedule so IE will look different all the time)
If you also pin the Internet Explorer tab to the taskbar, you will also have it look like this:
Tada1x
Nice huh?
Try to make some light changes to the css file as well, start out small. Use F12 Developer Toolbar and the arrow function to point to an object and find out what styles are applied and from what id/class they are coming.
It’s easy:
editcssx
Press F12, then use the arrow
editcss1x
Click on an object, like the site title
editcss2x
In the styles list you will now be able to find what gives the title its color and size:
.ms-core-pageTitle, .ms-corepageTitle a
and
.ms-core-pageTitle
Locate them in the local css, upload it and overwrite the old, reload the page, VOILA!
PageTitle
To continue, follow the next part of this SharePoint 2013 branding guide:
A guide to quick SharePoint 2013 branding – part 2 – with Javascript
This will allow you to use java to set the color and image of the top ‘chrome’. Even the Little buttons and toggles to the right. You will own them all.
Afterx

Creating Provider hosted app (sharepoint online) with local hosted IIS

The Pre-requires are as follows. 1. Office 365 Subscription 2. Visual Studio 2015 (Professional/Community/Enterprise Edition) With t...