Monday, July 21, 2014

Powershell function to send Email

Sending Email using Powershell 


Below is a script that can be used to send email using Powershell.


 $sd = new-object System.collections.specialized.stringdictionary
$sd.add("to","oumaima@example.com")
$sd.add("from","achkari@example.com")
$sd.add("Subject","Mail Sharepoint")
$web = get-spweb "http://Server_Name"
$body = "This is the email body"

[Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($web,$sd,$body)

Thursday, July 17, 2014

SharePoint 2013 Friendly URLs


SharePoint 2013 – Friendly URLs and Managed Navigation

An extremely powerful new feature in SharePoint 2013 and SharePoint Online is Managed Navigation.  Managed Navigation is a new option for global and context-sensitive navigation.  This new feature improves search engine optimization (SEO), provides cleaner URLs, and simplifies navigation management.  In this blog post, I will explain how to enable Managed Navigation.

Enabling Managed Navigation

It is very simple to enable Managed Navigation for publishing sites.  First, we need to select the Managed Navigation option in the Site Settings > Navigation page (shown below).
SP JG
Next we need to define the Managed Metadata term set that will be used for navigation (shown below).  The default term set is “Site Navigation” and it is set up to allow the same navigation across all Sites in the Site Collection.
SP JG2

Restore a SharePoint Site from a Database Backup

Restore a SharePoint Site from a Database Backup



We recently needed to restore a SharePoint 2013  site using only a database backup file. 
We assume that you have a SQL Server 2008 R2 backup of the SharePoint content database. We also assume that you are restoring to a different server than the original server, although either should work. Use the following steps:
  1. Copy the backup file to the new server and place in the directory where backups are normally kept. 
  2. Restore the backup file. 
  3. Start the SharePoint Central Administration application.
  4. Click on the Application Management.
  5. Click on the Create or extend Web application link.
  6. Click on the Create a new Web application link.
  7. Scroll down to the Application Pool section and decide whether or not you want to create a new application pool and what account you want to run under. Make sure that whatever account you use has the necessary permissions on the content database that you are recovering.
  8. Scroll down to the Database Name and Authentication section. Enter the name of the server where your backup data is installed in the Database Server text box and the name of the database in the Database Name text box. Click OK.
You should be able to access your site now.

Hope this help,
Oumaima

Wednesday, July 16, 2014

Adding Geolocation field to Sharepoint Online

Adding geolocation field to SharePoint Online


One of the hidden gems in Sharepoint is the new geolocation field. Geolocation field enables you to annotate SharePoint lists with location information. In columns of type Geolocation, you can enter location information as a pair of latitude and longitude coordinates. The reason it is hidden is because it is not available by default in SharePoint list and there is also no user interface to add it. The only way to add it is through code or powershell. There are already many posts with code samples for adding geolocation field so that wont be the topic of this post. I would suggest to you to check out this post http://zimmergren.net/technical/sp-2013-getting-started-with-the-new-geolocation-field-in-sharepoint-2013 if you want to get a good insight in those code samples. This post will describe how I have created a small wizard form for adding those fields to my SharePoint lists. I am using pure HTML and javascript so this will work both in SharePoint Online and in your on premise environment. First create a page where you wish to place this wizard. On that page add a Script Editor web part. In this web part we will add both our javascript methods and our html.
First add this javascript: 
?
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
81
82
<script type="text/javascript">
var clientContext;
var relativeAdress;
  
    function AddGeolocationField() {
  ClearNotifications();
  GetRelativeAdress();
        clientContext = new SP.ClientContext(relativeAdress); 
        var web = clientContext.get_web();
   
        var targetList = web.get_lists().getByTitle(document.getElementById('listname_input_id').value);
        var fields = targetList.get_fields();
        fields.addFieldAsXml(
            "<Field Type='Geolocation' DisplayName='" + document.getElementById('fieldname_input_id').value + "'/>",
            true,
            SP.AddFieldOptions.addToDefaultContentType);
        clientContext.load(fields);
        clientContext.executeQueryAsync(function (sender, args) {
       document.getElementById('success_id').innerHTML = "You have succesfully created new geolocation field.";
    },
    function (sender, args) {
        document.getElementById('error_id').innerHTML = "Error: "+args.get_message();
    });
    }
   
    function SetBingKey() {
  ClearNotifications();
  GetRelativeAdress();
        clientContext = new SP.ClientContext(relativeAdress);
   
        var web = clientContext.get_web();
        var webProperties = web.get_allProperties();
   
        webProperties.set_item("BING_MAPS_KEY", document.getElementById('bing_key_id').value);
        web.update();
        clientContext.load(web);
        clientContext.executeQueryAsync(function (sender, args) {
            document.getElementById('success_id').innerHTML = "You have succesfully entered BING map key on "+web.get_title()+" site";
        }, function (sender, args) {
              document.getElementById('error_id').innerHTML = "Error: "+args.get_message();
        });
    }
    function GetBingKey() {
   
  ClearNotifications();
  GetRelativeAdress();
        clientContext = new SP.ClientContext(relativeAdress);
        var web = clientContext.get_web();
         
        var webProperties = web.get_allProperties();
        clientContext.load(webProperties);
        clientContext.executeQueryAsync(function (sender, args) {
            document.getElementById('bing_key_id').value = (webProperties.get_fieldValues()["BING_MAPS_KEY"]);
           
        }, function (sender, args) {
            document.getElementById('bing_key_id').value = "";
            document.getElementById('error_id').innerHTML = "Property not found! Please check your web site relative URL.";
        });
    }
  
 function ClearNotifications(){
    document.getElementById('success_id').innerHTML = "";
    document.getElementById('error_id').innerHTML = "";
 }
  
 function GetRelativeAdress(){
  if (document.getElementById('webrelative_url_id').value === "")
            relativeAdress = "/";
        else
            relativeAdress = document.getElementById('webrelative_url_id').value;
  if(relativeAdress.charAt(0)!='/')
     document.getElementById('error_id').innerHTML = "Relative adress has to start with /";
 }
  
 </script>

And after that add this HTML form:

?
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
<table style="width: 480px;">
    <tbody>
<tr>
        <td style="width: 200px;">Web relative URL:
        </td>
        <td style="width: 5px;">&nbsp
        </td>
        <td valign="top"><input id="webrelative_url_id" name="relative" type="text" value="/">
            <label style="font-size: 8pt;">
                * Input web relative URL and select "Get BING key" to check if key is set</label>
        </td>
        <td style="text-align: right;" valign="top"><input onclick="GetBingKey()" type="button" value="Get BING key">
        </td>
    </tr>
<tr>
        <td style="width: 200px;" valign="top">Bing Maps Key:
        </td>
        <td style="width: 5px;">&nbsp
        </td>
        <td valign="top"><input id="bing_key_id" name="bingkey" type="text">
            <label style="font-size: 8pt;">
                * Input Bing map key and relative url to web site to wich you wish to add the key</label>
        </td>
        <td style="text-align: right;" valign="top"><input onclick="SetBingKey()" type="button" value="Set BING key">
        </td>
         
    </tr>
<tr>
        <td style="width: 200px;" valign="top">List name:
        </td>
        <td style="width: 5px;">&nbsp
        </td>
        <td valign="top"><input id="listname_input_id" name="listname" type="text">
            <label style="font-size: 8pt;">
                * Name of the list where you wish to add your new geolocation field</label>
        </td>
        <td></td>
    </tr>
<tr>
        <td valign="top">Field name:
        </td>
        <td style="width: 5px;">&nbsp
        </td>
        <td valign="top"><input id="fieldname_input_id" name="fieldname" type="text">
            <label style="font-size: 8pt;">
                * Name of the new geolocation field you wish to add</label>
        </td>
        <td style="text-align: right;" valign="top"><input onclick="AddGeolocationField()" type="button" value="Create field">
        </td>
    </tr>
</tbody></table>
<label id="error_id" style="color: red;">
</label>
<label id="success_id" style="color: green;">
</label>

This will be your end result: 


And now you have your form for adding geolocation field anywhere on your site collection. Once you have entered relative path to your web ("/" is root web) you can use Get Bing key to check if you have a BING maps key placed in that web and with Set BING key you can change or add a BING maps key to that web.

And once you enter List name and Field name you can use Create field to add a geolocation field with the name you specified to the list on the web.

Hope this helps you create you geolocation fields faster.

Sharepoint Designer 2013, XSLT List View Options ribbon option is not showing

Sharepoint Designer 2013, XSLT List View Options ribbon option is not showing I have an ordinary Wiki Page, also tried making an Article...