Development | @SPJeff

An Unhandled exception CryptographicException occurred in OWSTIMER.EXE

May 1, 2012 in Uncategorized

I recently saw this error while patching SharePoint with a Cumulative Update.   Most people will never see this.  However, you are not most people.  You run Visual Studio.  Smile

Visual Studio is trying to help us out with an unhandled exception by asking about launching debug.  That’s all well and good but I didn’t write the code and have no plans to change it.

Best way to work with this is to disable the JIT (Just-In-time Debugger) by following a few simple Registry Key changes:  http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/9e6cb3fb-f8fb-4c22-8608-e521e13260ff

 

image

Visual Studio Just-In-Time Debugger

An unhandled exception (‘System.Security.Cryptography.CryptographicException’) occurred in OWSTIMER.EXE [1344]

Programmatically enabling Records Management

June 19, 2011 in Uncategorized

Recently I had someone ask about how In-Place Records Management could be enabled in SharePoint 2010 for a given document with C# object model code.  The method ConfigureListForAutoDeclaration() was key to making everything work.  This would allow for easily enabling on many sites all at once.  Below I’ve included C# code and screenshots from the test site where it was enabled.  Please feel free to leave any questions below with a comment.

  • Open site
  • Enable “In-Place Records Management” site collection feature  (da2e115b-07e4-49d9-bb2c-35e93bb9fca9)
  • Open document library
  • Open “Record declaration settings”
  • Enable “Automatic Declaration” with [Microsoft.Office.Policy.dll]
  • Upload test files
  • Confirmed:  see padlock icon and unable to delete document library

 

C# – Visual Studio 2010 Console Application

Add assembly reference to [C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14ISAPIMicrosoft.Office.Policy.dll]

 

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Text;
   5:  using Microsoft;
   6:  using Microsoft.SharePoint;
   7:   
   8:  namespace SharePointConsoleApp1
   9:  {
  10:      class Program
  11:      {
  12:          static void Main(string[] args)
  13:          {
  14:              string siteURL = "http://sp2010";
  15:              using (SPSite site = new SPSite(siteURL))
  16:              {
  17:                  SPWeb w = site.OpenWeb();
  18:                  SPList dl;
  19:                  bool needToCreate = false;
  20:                  try
  21:                  {
  22:                      dl = w.Lists["Records"];
  23:                      Console.WriteLine("found");
  24:                  }
  25:                  catch (System.ArgumentException)
  26:                  {
  27:                      needToCreate = true;
  28:                  }
  29:   
  30:                  if (needToCreate)
  31:                  {
  32:                      //missing so create it
  33:                      Console.WriteLine("Records DL missing on " + w.Url);
  34:                      Guid g = w.Lists.Add("Records", "** Coporate Records Management **", SPListTemplateType.DocumentLibrary);
  35:                      w.Update();
  36:                      dl = w.Lists[g];
  37:   
  38:                      //enable auto-Record for uploads
  39:                      Microsoft.Office.RecordsManagement.RecordsRepository.Records.ConfigureListForAutoDeclaration(dl, true);
  40:   
  41:                      //add CEWP to default view
  42:                      dl = w.Lists[g];
  43:   
  44:                      //show on QuickLaunch
  45:                      if (!dl.OnQuickLaunch)
  46:                      {
  47:                          dl.OnQuickLaunch = true;
  48:                          dl.Update();
  49:                      }
  50:   
  51:                      //disable folders
  52:                      if (dl.EnableFolderCreation)
  53:                      {
  54:                          dl.EnableFolderCreation = false;
  55:                          dl.Update();
  56:                      }
  57:   
  58:                      //enable Content Types
  59:                      if (!dl.ContentTypesEnabled)
  60:                      {
  61:                          dl.ContentTypesEnabled = true;
  62:                          dl.Update();
  63:                      }
  64:   
  65:                      //disable Required Check Out
  66:                      if (dl.ForceCheckout)
  67:                      {
  68:                          dl.ForceCheckout = false;
  69:                          dl.Update();
  70:                      }
  71:   
  72:                      //add Content Type to default view
  73:                      Console.WriteLine("CT");
  74:                      SPField ctField = dl.Fields["Content Type"];
  75:                      SPView defaultView = dl.Views[dl.DefaultView.ID];
  76:                      defaultView.ViewFields.Add(ctField);
  77:                      defaultView.Update();
  78:                      dl.Update();
  79:                  }
  80:              }
  81:          }
  82:      }
  83:  }

Screenshots

image

DisplayName

Id

Scope

RecordResource

5bccb9a4-b903-4fd1-8620-b795fa33c9ba

Site

RecordsManagement

6d127338-5e7d-4391-8f62-a11e43b1d404

Farm

InPlaceRecords

da2e115b-07e4-49d9-bb2c-35e93bb9fca9

Site

RecordsCenter

e0a45587-1069-46bd-bf05-8c8db8620b08

Web

image

image

image

image

image

Best of SharePoint 2010 VSIX

April 20, 2011 in Uncategorized

The more I learn about Visual Studio 2010 the more I like it. For SharePoint developers, it is great to finally have a mature toolset. To make that experience even better the community has created several VSIX extensions as a “quick start” to more easily jump into various project types. Below I outline links to the VSIX extensions I am aware of and run locally. If you have any questions or suggestions please leave a comment.  Cheers!   Smile

 

image

 

CKS:DEV – Community Kit for SharePoint: Development Tools

http://cksdev.codeplex.com/

SharePoint Foundation 2010 version and SharePoint Server 2010 version

WSPBuilder conversion tool (WCT) beta

Improved Quick Deploy

Keyboard shortcuts

Updated Full Trust Proxy SPI

Restart processes menus

Attach to processes menus

Solution level Package all

Improved import Content Types

Branding SPI

Improved Fluent visual web part SPI

Basic service application SPI

WCF service SPI

SharePoint PowerShell cmdlet SPI

SharePoint PowerShell pipe binding SPI

Improved copy assembly name menu

SharePoint 2010 Extensibility Projects

http://archive.msdn.microsoft.com/vsixforsp/Release/ProjectReleases.aspx

  • Silverlight and SharePoint project template
  • SharePoint Ribbon project template
  • OBA Deployment project template

Visual Studio 2010 SharePoint Power Tools

http://visualstudiogallery.msdn.microsoft.com/8e602a8c-6714-4549-9e95-f3700344b0d9

  • Sandboxed-compatible Visual Web Part
  • Sandboxed Compilation

Silverlight SharePoint Web Parts

http://visualstudiogallery.msdn.microsoft.com/e8360a85-58ca-42d1-8de0-e48a1ab071c7

  • Silverlight Web Part
  • Silverlight Custom Web Part

SharePoint 2010 Timer Job

http://visualstudiogallery.msdn.microsoft.com/ab2b2d63-de37-4f63-b4b0-442f80b59b00

SharePoint 2010 Console Application

http://blah.winsmarts.com/2011-2-SharePoint_2010_Console_App,_Project_Template.aspx

LINQ to SharePoint DSL Extension for Visual Studio 2010

http://archive.msdn.microsoft.com/linq2spdsl/

Windows Azure – publishing from Visual Studio 2010 (step-by-step with screenshots)

March 27, 2011 in Uncategorized

Today I deployed my first Azure application and documented the step-by-step process with detailed screenshots.

First I downloaded the Azure SDK and prepared Visual Studio 2010.   Azure is a cool idea because of the support for highly scalable custom code.  One frequent objection to cloud hosting is the basic functionally.   Cloud providers tend to offer what’s easy and convenient … while avoiding custom code.    Hybrid models may be the resolution.  Architects who can connect multiple vendors seamlessly or blend on-premise with in-cloud servers will be in demand.

  • Download the Azure SDK
  • Locate the first Hands On Lab (HOL) “Introduction to Windows Azure”
  • Code and build in Visual Studio 2010
  • Verify local Azure Emulator is working (files / SQL database / Compute)
  • Deploy to Azure in the cloud  (NOTE – this is  lot of work the first time,  must get connected and trusted)

 

image

 

We begin with the "Guest Book” sample application which allows you to post messages on a common wall with a picture attached.  Simple enough.

image

image

 

Here you can see the tray Azure Emulator running the website locally on my laptop.   For development you want to run things locally, test, and deploy to the cloud when stable.

image

image

 

Right clicking on the tray icon allows you to view Emulator status, logs, and details.   You can restart and control instances here.

image

 

Out of curiosity I opened SQL Management Studio  and viewed the “SQLEXPRESS” instance (which the default for the Azure SDK examples).  Here you can see the databases and tables this sample created.  The schema appears very abstracted.   From Visual Studio 2010 all I saw were strongly typed Classes and Objects for data.   Somehow that is being flattened to a database table using the Azure binaries, pretty cool.

image

 

Here is the Visual Studio 2010 Solution Explorer showing the 3 projects and related files inside of the “Guest Book” sample application.

image

 

OK, let’s get to the fun part.   Open a web browser, navigate to https://windows.azure.com/default.aspx and login to Windows Azure Platform Management.  There is some new vocabulary which be confusing at first.   First, create a new “Hosted Service.   This can take 5-10 minutes to provision so be patient.

image

 

Once the “Hosted Service” shows “Created” then we must add a “Storage Account” for the ability to hold data in the cloud.

image

 

Certificate trusting the local laptop’s Visual Studio 2010 to publish.   This is a LOT of work, but only a one time operation.  Let’s get started.   Right click on your Azure project within the solution explorer and click Publish.

image

 

The first time here we need to Add Credentials.

image

 

To pair the local Visual Studio with the Azure cloud, we need a certificate.   Since this is our first time, create a new one.  Name it whatever you like.  I chose to name mine after the development laptop “JEFF-PC”

image

image

 

Click “copy the full path” to populate the clipboard with the local file path.

image

image

 

We’re going to leave Visual Studio 2010 for a minute, but keep it open in the background since we’ll be back.  In the web browser go back to Windows Azure Platform Management.  Click “add certificate” and paste the local .CER file path from the previous setup.

image

image

 

Click on the “Subscription” line item to view the “Subscript ID” number.  Copy this to the clipboard.  You will need to give that to Visual Studio 2010 locally for publishing.

image

 

Back in Visual Studio 2010 we need to finish the Add dialog by giving it two values:   Subscription ID and Name.

image

image

image

image

image

Congratulations!!   Hot  You’ve successfully connected your local Visual Studio 2010 to the Azure Subscription.   You should now see three cascading drop down menus with the Azure cloud deployment destinations.

STSADM CMD with email output

July 11, 2010 in Uncategorized

Waiting and watching STSADM run on the CMD line is an exercise in patience.  Lately I’ve been incorporating two techniques to email myself updates for the freedom to walk away from the keyboard.

A quick command line EXE project allows me to send email by giving parameters (number 0-5).   If 5 is blank, no big deal just send a plain email with subject and body.   If 5 exists then attempt to open that text file, read content, and send as email body.

That’s great, but … how does this help me?  Great question!!

1) Send email at key script milestones

The freedom to walk away and receive alerts as progress continues allows you to be stay confident and know progress is moving forward.  Just add “SendMail.exe” inline with your existing CMD files to send an email at that step in the process.

 

2) Send email with script outcome

The detailed knowledge of what return value came from the CMD when it finished is helpful.   Imagine running a site move (STSADM backup/delete/restore) and heading out for dinner.   It’s very nice to get an email showing “Operation completed successfully” three times.  Smile   Just use “SendMail.exe” with parameter 5 being the text file full path and name.

image

image 

using System;
using System.Collections.Generic;
using System.Text;

using System.Net.Mail;
using System.IO;

namespace SendMail
{
    class Program
    {
static void Main(string[] args)
{
    //0-from
    //1-to
    //2-subject
    //3-body
    //4-server
    //5-filename

    string textFile = "";
    if (!String.IsNullOrEmpty(args[5]))
    {
        //send text file as body
        TextReader tr = new StreamReader(args[5]);
        textFile = tr.ReadToEnd();
        tr.Close();
    }

    //create message
    Console.WriteLine("from {0} to {1} subject {2} body {3} on server {4}", args[0], args[1], args[2], args[3], args[4]);
    MailMessage message = new MailMessage(args[0], args[1], args[2], args[3]);

    //if file was given modify body
    if (textFile != "") message = new MailMessage(args[0], args[1], args[2], textFile);
    SmtpClient emailClient = new SmtpClient(args[4]);
    emailClient.Send(message);
}
    }
}

Unlock ASMX for easy manual invoke (developers)

July 6, 2010 in Uncategorized

For SharePoint development I like to use the .ASMX web services for reading data.  Out of the box default security prohibits manual remote HTTP queries.  A quick edit to “C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12ISAPIweb.config” for changing <protocols> from “remove” to “add” and then you’ll be able to manually Invoke.

The raw XML returned by a manual invoke is incredibly valuable for developers.  Open-mouthed

Before (out of the box)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration>
    <system.web>
        <webServices>
            <protocols>
                <remove name="HttpGet" />
                <remove name="HttpPost" />
                <remove name="HttpPostLocalhost" />
                <add name="Documentation" />

image

After (unlocked for development)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration>
    <system.web>
        <webServices>
            <protocols>
                <add name="HttpGet" />
                <add name="HttpPost" />
                <add name="HttpPostLocalhost" />

                <add name="Documentation" />

image

Always use CMD files

July 3, 2010 in Uncategorized

I rarely use absolutes but CMD files are amazing and you really should always use them.  For anything, no matter how small.

Why bother?  What’s in it for me?

  1. Easy to repeat
  2. Easy to test
  3. Can modify while running

The only cost is time.  It takes a little longer to build a CMD file and plan it out.  However, measure twice and cut once pays off with quality.  Let’s explore the benefits one at a time:

  1. Reusing a CMD file is very easy.  Search replace in Notepad++ can switch scope easily.  Also, input parameters like %1, %2, etc. can make the tool modular for using in a slightly different way quickly next time.
  2. Copy a CMD file to lower environments for practice is quick, easy, and helps mitigate risk.  Before you typo against production, try copying the file to a different server first.
  3. This is awesome and very little known!   While a CMD file is running (after you hit enter) you can still open Notepad.exe and modify the file.  Adding an extra line, commenting out with REM, or removing a line can all be done.  As long as CMD has not made it down to that line already you’re edits will be picked up as it steps down.   Great for real-time adjustments.

Thanks for reading!  Open-mouthed

image

HowTo: Append “ToolPaneView=2” to edit ASPX forms (New, Edit, Display)

May 12, 2010 in Uncategorized

Have you ever wanted to add a web part to a SharePoint page (New, Edit, Display Form) and not found the “Edit Page” option under Site Actions?  Here’s a little trick for getting into Edit Page mode.

clip_image002

Add ?PageView=Shared&ToolPaneView=2 to the end of your URL and hit enter.

You’ll now be in edit mode and can add additional web parts to your page. Easy!  Smile

clip_image004

DevAdmin = Best job title!

April 25, 2010 in Uncategorized

Admins and Devs seem different.  They often argue, yet can learn from each other.  I’ve done both and neither is the complete picture.   Below is an idea for scripting, scaling, and growing by learning both.  “DevAdmin” is a role with incredible potential.   Please leave a comment, email me, or send a tweet.   I’d really like to hear your feedback.

Dev   Admin
  • Says “yes”
  • Goal = More features
  • Liberal approach
 
  • Says “no”
  • Goal = More stability
  • Conservative approach

Above is my stereotype of both groups.  While not perfect it’s a useful frame of reference.  When speaking to one group (or the other) keep their unique perspective in mind to communicate more clearly.  Below is an outline for mixing both to create a more balanced IT worker:

DevAdmin
  • Says “maybe” and listens
  • Goal = Stable features
  • Liberal on features, Conservative on process
  • Knows both sides, actively works on both

image

RDP sucks at scaling.  But it’s great for small tasks.  How do you admin 300 servers?  Hmm … that’s a bunch of windows to juggle!  Confused   I developed a working concept called the “grid” script that would place real-time configuration on a single page.  Each machine/server is a vertical column.   Each configuration point is a row.   On a single page I can tell exactly what settings are missing, where changes are needed, and ensure high quality with lower costs.   I must be a DEV to code this tool.   I must be an ADMIN to read and use it.

http://spdash.codeplex.com/

I’ve reserved the URL above to place my code and EXE once complete for all to enjoy.   More to come soon …

image
image

image

The technology environment will only grow more complex.   ADMINs must learn some DEV (script, powershell, dot net, etc.) to remain marketable.   DEVs must learn some ADMIN (performance, capacity, uptime) to know how to scale up their application and ensure stable delivery to end users.

Related Posts

Workflow History – Event Type Numbers Decoded

January 29, 2010 in Uncategorized

On a SharePoint site’s hidden Workflow History list you might stumble across some strange numbers.  The Event Type is used to store a numeric value and below I’ve listed what each means in plain English.

These map to Microsoft.SharePoint.Workflow.SPWorkflowHistoryEventType which contains their values in Visual Studio for developers.

Unfortunately MSDN does not list the numeric values for use by power users to create filtered views in the browser.   However, I have them here:

 

Number Event Type
0 None
6 TaskCompleted
5 TaskCreated
9 TaskDeleted
7 TaskModified
8 TaskRolledBack
3 WorkflowCancelled
11 WorkflowComment
2 WorkflowCompleted
4 WorkflowDeleted
10 WorkflowError
1 WorkflowStarted

 

image

 image

Return to Top ▲Return to Top ▲