Tag Archives: Development

STSADM CMD with email output

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)

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)

 
 
     
         
             
                 
                 
                 
                

image

After (unlocked for development)

 
 
     
         
             
                 
                 
                 
                

image

Always use CMD files

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

DevAdmin = Best job title!

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

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:

 

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

 

image

 image

SPD Best Practice: Ctrl C+V Quick Backups

To quote Asif Rehmani (@asifrehmani) from www.sharepoint-elearning.com … “SharePoint Designer is like a really sharp knife.   It’s very good at what it does.   You might cut yourself.   But you don’t stop, just act more carefully.”

 

With that lesson well learned over my years with SharePoint customization I must say my favorite trick of all is the simple quick copy/paste backup.   Any time and every time I’m about to jump off a cliff to dive into SPD coding I perform a Quick Backup:

  • Highlight the file
  • Ctrl+C    (copy)
  • Ctrl+V    (paste)
  • Breathe a sigh of relief

Storage is cheap.   Mistakes are not.   Time is one of our most scarce resources.   Buy some insurance with a Quick Backup!   Hot

 

image

image

Why the /Forms/ folder is your friend

I’ve been working with custom views for a few years now and one thing seems to always come up … Where to put those pesky resource files?    Images, JavaScript, User Guide PDF, all of these I’ve used in one way or another.    Tweaking DispForm.aspx is a past time of many SharePoint developers but how many know of a proper place to drop their resource files?     The /images/ folder of the web is intriguing but leads to a disconnected management experience.   What if this list is deployed to another site with a duplicate file of the same name?  (naming conflicts)

 

I will submit the idea that the hidden system folder /Forms/ is a great place for these for four simple reasons:

  1. Easy to find – Yes, I get lost on my own sites.   Don’t you?   Having the resources nearby makes management a breeze.
  2. Relative URL hyperlinks – No need for server relative or hardcoded URL reference.    From DispForm.aspx (for example) just call “resource_file.ext”
  3. Protected from end users – They can’t delete what they can’t see.   Enough said.
  4. Bundled as .STP for list templates – When you save any SPList as STP it will automatically package up the entire contents of the /Forms/ folder.   How cool is that!?!    So easy to migrate, duplicate, and even control source version history by saving often.    This alone is reason to use this technique.

 

So the next time you’re adding custom files to a particular list please give the /Forms/ folder a second look.  Hot

 

image

 

image

 

image

The Ultimate SharePoint 2007 Virtual Machine (VHD)

I maintain a local virtual machine on my laptop to evaluate, explore, code, and learn.    It’s one of my best tools and I find it incredibly useful each day.    It also needs refreshing and upkeep like any other technology.    Patches, new features, and experience compel me to make adjustments as time goes forward.   

 

I’ve completed my latest build and wanted to lay out the specifications here in case it’s helpful to other people building a similar virtual machine for their own work.   Admins, developers, and even business analysts can benefit from having a local fully autonomous and fully featured SharePoint server.

 

image

 

VHD Format
Ready for immediate use on any VM system
WinRAR split across 20 files (700 MB) for a total 13.2 GB download with a built in EXE extractor.   No need to have WinRAR for extraction.
Note – No integration services are pre-loaded.   If you’re using Microsoft Virtual PC, VMWare, or Hyper-V these come with an option to load integration for a smoother experience working inside of the running guest VM (moues pointer, disk drives, keyboard shortcuts, etc.)

Applications Installed
Adobe Reader 9.1.0
Adobe Flash for IE
IE 8.0
IE Developer Toolbar
Notepad 2.0
Performance Point Server 2007 – Planning and Monitoring Servers
Office 2007 Professional
Office Save as PDF Add-In
Office Groove 2007
Outlook 2007 with email profile configured (workflow / alert demos)
SharePoint Designer 2007
Visio 2007
Project Professional 2007
iFilter pack for Office 2007 formats
Visual Studio 2008 Team Suite Edition  (incl Architecture, Database, Development, and Test)
Visual Studio Tools for Office (VSTO)
Visual Studio Add-In for MS Chart 3.5
Visual Studio Add-In for WSS Extensions v1.3
SDK – WSS CHM Documentation
SDK – MOSS CHM Documentation
Exam Diff Pro with right click integration and plugins for comparing PDF, XLS, DOC, etc.
SQL Server 2005 Enterprise Edition – with Database, Analysis, Reporting, and Integration
SQL Server Reporting Servers – BOTH native and integrated instances
SQL Server Management Studio – Full
SQL Profiler
SQL Sample Databases – Adventure Works, Northwind, Pubs
SQLCMD
SharePoint Server 2007 Enterprise Edition
Windows SharePoint Services patched to August 09 Cumulative Update (12.0.6514)
STSADMWin – GUI for STSADM command line to avoid typos and speed up routine tasks
Filezilla – Free FTP client
MagicDisc – Can host ISO files as drive letters
ZoomIt – Great for presentations!   Zooms to one part of the screen for easy back-of-the-room reading
TreeSize Professional – Show disk consumption by folder branch
IIS 6.0 Resource Kit
IIS 6.0 Diagnostic Kit
SharePoint Manager 2007
Stramit CAML Viewer 2007
Enterprise Library 3.1
SpsDev.com ULS Log Reader
SharePoint Skinner

O/S Installed
Windows Server 2003 SP2 Enterprise Edition x86
Single C: partition expandable up to 30GB with 10GB free space
Defragged already
Active Directory
POP3 and SMTP email for local "training.corp" domain
"administrator@training.corp" is the default email address for TRAININGADMINISTRATOR
Netmon 3.3
Visual Round Trip Analyzer
Windows 2003 Server Resource Kit
CmdHere right click menu integration
Windows Automatic Updates are Disabled to avoid surprises and let you manage manually

 

image 

image

image

image

image

image

image

image

image

image

_WPQ_ with Javascript for dynamic lookup

If you’re using the trusty CEWP (Content Editor Web Part) to locate the current web part frame on a page you’ll want to consider using the “_WPQ” expression instead of hard coding a number.    Using the Internet Explorer Developer toolbar or Firebug toolbar is a great way to locate <DIV> tags and “ID=” attributes with a single click.

However, don’t be tempted to code in the number.    As you re-order web parts they will changes.    If you add more than one CEWP (export/import) the others will fail.    Use a dynamic token for maximum flexibility.

SharePoint’s rendering engine does a search replace on “_WPQ_” to give it the number of that web part on the page.   It’s a great way to avoid naming conflicts and a trick I’ve used to apply multiple JQuery driven CEWP on the same page.

 

References

image

Return to Top ▲Return to Top ▲