CHUVASH.eu
  • About
  • Search

Posts

September 21, 2011

Do an unsafe update in a unified manner

Recently I talked about a WithWeb-pattern as described in Jonas Nilssons blog where you can isolate the disposal logic in one place. Another thing is to isolate unsafe updates:

public static class SPWebExtension
{
    public static void UnsafeUpdate(this SPWeb web, Action<SPWeb> action)
    {           
        try
        {
            Log.Info("Trying to do an unsafe update on a web: " + web.Title);
            web.AllowUnsafeUpdates = true;
            action(web);
        }
        catch (Exception e)
        {
            Log.Error(e);
        }
        finally
        {
            web.AllowUnsafeUpdates = false;
        }
    }
}
```The Log class is my own class which I presented in [my previous post](https://sharepointkunskap.wordpress.com/2011/09/19/a-simple-log/).

## Comments from Wordpress.com


#### 
[WithWeb-pattern of Jonas Nilsson &laquo; Sharepoint. Kunskap. Upptäckter på resan.](https://sharepointkunskap.wordpress.com/2011/09/15/withweb-pattern-of-jonas-nilsson/ "") - <time datetime="2011-09-21 17:28:23">Sep 3, 2011</time>

\[...\] Here I use another fancy way to consolidate the unsafe updates. \[...\]
<hr />
read more
September 21, 2011

Show Title on Page

If you want to show the page title in another part than defined in your master page just add this tag to your page layout.

<SharePoint:ProjectProperty 
    Property="Title" runat="server" />
```It must be within <asp:Content> tag
read more
September 21, 2011

Show a presence bubble

There is no built-in sharepoint control for the presence bubble. If you want to add this functionality on your pages you have to add it as html. Here is a sample:

private static int \_COUNTER = 0;
private const string PresenceBubble =
    "<a class='ms-imnlink' href='javascript:;'>" +
    "<img width='12' height='12' id='imn\_pawn\_{0}' onload=\\"IMNRC('{1}')\\" alt='My SID' " +
    "src='/\_layouts/images/imnoff.png' border='0' " +
    "showofflinepawn='1' sip='{2}'></a> {3}";

private static string FormatUser(SPUser user)
{
    \_COUNTER++;
    return string.Format(PresenceBubble, \_COUNTER, user.Email, user.GetSipAddress(SPContext.Current.Web), user.Name);
}
read more
September 21, 2011

Get role assignments of a web or a list

In Powershell you can easily get the permissions in a web or in a list:

$web = get-spweb http://contoso.com
$web.Groups | select Name, Roles > .\\Desktop\\webgroups.txt
$list = $web.Lists.TryGetList("Assets");
$list.RoleAssignments | select Member, RoleDefinitionBindings > .\\Desktop\\assets-roleassignements.txt
```To get all users in all groups run:

$web.Groups | Foreach { Write $_.Name; Write “————-”; $_.Users | Select Name; Write “”; Write "" }

read more
September 21, 2011

Windows 8 preview

windows 8I have tested the Windows 8 developer preview. VMWare player 3 didn’t manage it, so I installed VirtualBox and it ran very well. One thing I did was to enable full screen on VirtualBox. Here is the list of features you get if you install the developer preview:

  • Windows SDK for Metro style apps
  • Microsoft Visual Studio 11 Express for Windows Developer Preview
  • Microsoft Expression Blend 5 Developer Preview
  • 28 Metro style apps including the BUILD Conference app
read more
September 20, 2011

Singleton vs static

Have you wondered what to use a singleton object  or a class with static methods. Well, here is an awesome comparision of these techniques. Static methods and classes are easy to use, but you can’t them as objects, implement interfaces and have constructors with parameters.

read more
September 19, 2011

A simple Log for ULS

Do an unsafe update in a unified manner « Sharepoint. Kunskap. Upptäckter på resan. - Sep 3, 2011

[…] Log class is my own class which I presented in my previous post. Like this:GillaBli först att gilla denna […]

read more
September 19, 2011

A simple Log for ULS

Here is a simple log which has been inspired of Android Log. It logs to ULS which you can open with ULSViewer, SharePoint Log Viewer.

using System;
using Microsoft.SharePoint.Administration;

namespace Contoso.Intranet.Portal.Utilities
{
    public class Log
    {
        private static readonly string \_CATEGORYNAME = "CONTOSO";
        private static readonly SPDiagnosticsCategory \_ERROR\_CATEGORY = 
              new SPDiagnosticsCategory(\_CATEGORYNAME, TraceSeverity.Unexpected, EventSeverity.Error);
        private static readonly SPDiagnosticsCategory \_WARNING\_CATEGORY = 
              new SPDiagnosticsCategory(\_CATEGORYNAME, TraceSeverity.High, EventSeverity.Warning);
        private static readonly SPDiagnosticsCategory \_VERBOSE\_CATEGORY = 
              new SPDiagnosticsCategory(\_CATEGORYNAME, TraceSeverity.Verbose, EventSeverity.Verbose);
        private static readonly SPDiagnosticsCategory \_INFO\_CATEGORY = 
              new SPDiagnosticsCategory(\_CATEGORYNAME, TraceSeverity.Medium, EventSeverity.Information);

        private static void WriteTrace(SPDiagnosticsCategory category, string message, string trace)
        {
            SPDiagnosticsService.Local.WriteTrace(0, category, category.DefaultTraceSeverity, message, trace);
        }

        public static void Error(Exception ex)
        {
            WriteTrace(\_ERROR\_CATEGORY, ex.Message, ex.StackTrace);
        }

        public static void Warning(string message)
        {
            WriteTrace(\_WARNING\_CATEGORY, message, "");
        }

        public static void Verbose(string message)
        {
            WriteTrace(\_VERBOSE\_CATEGORY, message, "");
        }

        public static void Info(string message)
        {
            WriteTrace(\_INFO\_CATEGORY, message, "");
        }

    }
}

A possible improvement can be a custom Area. See an example of ThorstenHans on Github: CustomLogger.cs EDIT: I found an interesting article: How to log to the SharePoint ULS Logs: Clean Debugging and Error Logging broken down into steps written by Philip Stathis.

read more
September 19, 2011

1DayLater.com - the best time tracking

I discovered a great tool for time tracking: 1DayLater. So far I am very pleased. You can add activities, write hash tagged descriptions, get an overview over you consultant hours and much more

read more
September 19, 2011

My favorite tools

When you code, you can save a lot of time and nerves if you have good tools. Here are my favorites: Programmer’s notepad ULS Log Viewer Resharper t4toolbox HTML5 and CSS3 standards

read more
  • ««
  • «
  • 37
  • 38
  • 39
  • 40
  • 41
  • »
  • »»
© CHUVASH.eu 2026