Skip Ribbon Commands
Skip to main content
Home > SharePoint Online Code
December 15
Powershell script to get correlation ID for SharePoint Logs

Change the variables for correlation ID and the 2 dates and return all timestamps and messages for that correlation id from all your SharePoint logs.

 

 
# Defining script variables
$CorrelationID = "6fc9f8e8-e179-4815-9c02-f5239214e192"
$StartDate = "12/15/2011 05:50:30"
$EndDate = "12/15/2011 20:50:35"
#Loading Microsoft.SharePoint.PowerShell

$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null) {
Write-Host "Loading SharePoint Powershell Snapin"
Add-PSSnapin "Microsoft.SharePoint.Powershell"
}


    Write-Host "Retrieving ULS events by correlation ID"
    $events = Get-SPLogEvent -StartTime $StartDate -EndTime $EndDate | Where-Object {$_.Correlation -eq $CorrelationID}
    $events | Select Timestamp, Message | Format-List

August 14
Blogs dont work work with public website in SharePoint online

Seems the blogs are crippled in SharePoint Online anonymous access is only available to the main blog page, categories and links to specific content cause access denied errors.​

August 12
Create an Sharepoint Event Reciever for list adds and updates

When creating a event receiver your biggest problem is making sure that you do not reference an object that was created under a user that does not have sufficient privileges. To accomplish this make sure that every object is created inside the SPSecurity.RunWithElevatedPrivileges method.

I have not tried this with SharePoint Online and will update this when I do. In theory it should work in both.

Here is the sample :

 

using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;

namespace Demo.ListSecurityEventHandler
{
    /// <summary>
    /// List Item Events
    /// </summary>
    public class ListSecurityEventHandler : SPItemEventReceiver
    {
        /// <summary>
        /// An item was added.
        /// </summary>
        public override void ItemAdded(SPItemEventProperties properties)
        {
            base.ItemAdded(properties);

 

            try
            {

 // key is RunWithElivatedPriviledges and don't reference a previously created object doing so 
// will cause you to run under the user that created it.
                SPSecurity.RunWithElevatedPrivileges(delegate
                {
// I am running the same code on the item added and item updated so put it in a function.
                    SetInternalPermissions(properties);
                });
            }
            catch (Exception)
            {

 
            }

        }
        public override void ItemUpdated(SPItemEventProperties properties)
        {
            base.ItemUpdated(properties);

            try
            {

                 SPSecurity.RunWithElevatedPrivileges(delegate
                {
                    SetInternalPermissions(properties);
                });
            }
            catch (Exception)
            {

            }

         }
        public void SetInternalPermissions(SPItemEventProperties properties)
        {
//open the a new site with the site id it is just a guid and will not cause an object reference to the current user.
            using (SPSite siteCollection = new SPSite(properties.SiteId))
            {
// again use the string value so no object reference is used that would run under the current user
                using (SPWeb objWeb = siteCollection.OpenWeb(properties.RelativeWebUrl))
                {
                    string curRelativeUrl = string.Empty;
                    if (properties.RelativeWebUrl != "/")
                    {
                        curRelativeUrl = properties.RelativeWebUrl + "/";
                    }
// again no object reference
                    SPListItem item = objWeb.GetListItem(curRelativeUrl + properties.ListItem.Url);
//Use the content type to find to identify if this is a list you want to do something with
                    if (item.ContentType.Name == "Your Content type name")
                    {
                        string itemText = (string)item["Your Property name"];
//check the property and do what you need to
                        if (itemText == "What ever you want to check for")
                        {
                            //add what ever you want here
                        }
                    }
              }
            }
         }
    }
 }

 

August 11
Add Deploy and Remove Solutions

Here are two simple funtions the first adds and deploys a solution to a specific application with a GAC deploy.

 #the variables below need to be set for all to work correctly
#**********************************************************************************************
 $siteURL="Http://server:port/sites/sitename"
 $webApp = "Http://server:port"
 $deployFolder = "c:\deploy\"
 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


#Functions deploys to web application and GAC other switches can be added
#******************************************************************************
function AddDeploySolutions( [string]$wsp, [String]$wspPath, [string]$siteurl, [string]$webApp)
{
    Add-SPSolution ($wspPath + $wsp)
    Install-SPSolution –Identity $wsp –WebApplication $webApp  -GACDeployment
   
}
 
#example call
AddDeploySolutions "filename.wsp" $deployFolder $siteURL $webApp
# pause below is only needed if there is a another call like enable feature after

Start-Sleep -s 60
#the following enable a feature that has been deployed

Enable-SPFeature -Identify "featurename" -URL $siteURL -force

And the Second function unistalls and removes a solution.

Function RemoveSolution([string]$wsp)
{
    $solution = Get-SPSolution | where-object{$_.Name -eq $wsp}
   
    if ($solution -ne $null)
    {
        if($solution.Deployed -eq $true)
        {
        Uninstall-SPSolution -Identity $wsp –AllWebApplications -Confirm:$false
           Start-Sleep -s 60
           Remove-SPSolution -Identity $wsp -Confirm:$false
        }
        else
        {
        Remove-SPSolution -Identity $wsp -Confirm:$false
        }
    }
}

#example function call

RemoveSolution "filename.wsp" $webApp

August 11
SharePoint Online how to activate the Publishing Feature for the Root Public Website

Use at your own risk. No warranty is given.

To be able to use the publishing feature in a root Public Website you must open the site with Sharepoint Designer. Click on All Files then rename the following. (to rename right click on each of the following and click rename)

  1. Documents
  2. Images (folder)
  3. Pages
  4. SiteImages
  5. TemplateGallery

Then Click on List and Libraries and rename the following

  1. Documents
  2. Web Pages
  3. Templates
  4. Image 

 

You then need to get to site settings. To get to site setting add this to the end of your root url /_layouts/settings.aspx.

Example http://www.sharepointonline.net/_layouts/settings.aspx

Once there click on Site Collection Features under Site Collection Administration. Then Activate the SharePoint Server Publishing Infrastructure feature.

Go back to site settings and click on Manage Site Features under site actions. Then Activate the SharePoint Server Publishing Feature.

You now have a site with the publishing feature activated.

Finally go to Site Actions View all site content and create a new page set this page to the home page.

You should now have a functioning publishing public website.

Link to another site that shows this technique

http://www.martinhatch.com/2011/07/how-to-configure-your-office365-public.html

and also states that this is an acceptable to microsoft in the following link http://community.office365.com/en-us/f/153/p/8015/34893.aspx#34893

 

August 10
Welcome to SharePoint Online Code Blog!

My plan is to add code and insight to this blog on an ongoing basis. Which will serve as reference for me and hopefully help anyone who reviews the information.

 

 About this blog

 

About this blog

Mark Greve

SharePoint Architect

Strategic Computin Inc.

303-796-0748 ext 30

303-693-1993

Mark.Greve@

SharePointOnline.net