Skip to main content

Mark Wagner - Cogitation Blog

Go Search
Blog
SPDev
Wiki
Governance
  

Welcome
Mark Wagner works for Microsoft in the West Region specializing in Microsoft .NET and SharePoint technologies.
My old blog (still filled with goodies)
Need Web Hosting?
I host part of my site here. The best value for quality hosting. Read my opinion here. If you decide to join, please use this link, and thank you very much.
Legal
Any and all code, software, examples, suggestions and anything else on this web site is available for you to use at your own risk. No warranty is express or implied.
Views and Opinions
Mark Wagner works for Microsoft in Consulting Services covering the West Region. The views and opinions expressed on this web site are not necessarily the views or opinions of his employer.
Popular Posts
How To: Hide/Remove the View All Site Content link in SharePoint100
How To: Modify the web.config file in SharePoint using SPWebConfigModification38
Apply a Theme to all sub sites in SharePoint 200718
Fix: This connection requires an active Internet connection16
Create Custom SharePoint Web Service WSDL and Disco ASPX Files Automatically15
Recent Posts
Create Custom SharePoint Web Service WSDL and Disco ASPX Files Automatically
SharePoint RunWithElevatedPrivileges Example
Create a Live Meeting ‘Meet Now’ link in your email signature
Logging to the SharePoint Log Files
How To SysPrep Your Virtual PC/Virtual Server Images
Unauthorized (401.1) Exception calling Web Services in SharePoint
I'm mentioned (twice) in an MSDN Magazine article - SWEET!
Apply a Theme to all sub sites in SharePoint 2007
SPSecurityTrimmedControl: Conditionally display contents by security
How To: Create a SharePoint Solution for an InfoPath Form
Configuring Alternate Access Mappings for a Web Application (DRAFT).wmvConfiguring Alternate Access Mappings for a Web Application (DRAFT)
How to change the Central Admin tcp port number.wmvHow to change the Central Admin tcp port number
Incredible Blogs
Simple thoughts on .NET Development, C#, and SharePoint Technologies
Create Custom SharePoint Web Service WSDL and Disco ASPX Files Automatically
Update: The details for this posting have been moved to its own site here.
 
I just completed a SharePoint developer tool called SPDev.exe. The initial purpose of this utility is to auto-generate the web service WSDL.aspx and Disco.aspx files needed for a custom SharePoint web service.
icon_shout_10 Automatically generate your SharePoint disco.aspx and wsdl.aspx files in seconds!
icon_shout_10 No need to manually copy or deploy your .asmx first!
icon_shout_10 No manual editing!
icon_shout_10 No Disco.exe needed!
icon_shout_10 Automatically recycles the application pool (ensuring the newest assembly is loaded)!
icon_shout_10 Automatically deploys the final SharePoint web service files (using the -deploy option)!
icon_shout_10 No UI to enter data each time.  A command tool you can script for fast, consistent re-use!

After having to manually modify the disco.aspx and wsdl.aspx files by hand for the last three years, I finally found it tedious enough to create this utility.  There are other tools out there, but they require you to enter information into a Windows UI, they are not script-able, and still felt to tedious for me.  Call me lazy.  :)  Time is money.  This tool is a command line utility.  Simply execute the SPDev.exe command and your MyServiceDisco.aspx and MyServiceWsdl.aspx files are immediately ready for deployment.  SPDev also allows you to script the process.  Create a .cmd or .bat file and you’ll never have to enter any parameters again.  Another big benefit is you don't need to use the Disco.exe utility since SPDev uses IIS and .NET instead which will always be on your development machine - since you are developing for SharePoint.  And, there are no temp files are generated (unless you want them generated).

Update: The details for this posting have been moved to its own site here.

SharePoint RunWithElevatedPrivileges Example

The following example sends an email using elevated privileges.  This will elevate the privileges to execute using the service account.

The SPSecurity.RunWithElevatedPrivileges method taks a delegate method as its argument and executes that code with the service account.

SPSecurity.RunWithElevatedPrivileges(
    delegate()
    {
        // Your code needing elevated permissions goes here.
    }
)

public void SendEmail(Email email)
{
   SPSecurity.RunWithElevatedPrivileges(
      delegate()
      {
         SmtpClient mail = new SmtpClient();
         MailMessage message = new MailMessage();
 
         message.From = new MailAddress(this.SenderAddress);
 
         message.To.Add(email.To);
         message.IsBodyHtml = email.IsHtml;
 
         if (!string.IsNullOrEmpty(email.Cc))
            message.CC.Add(email.Cc);
 
         if (!string.IsNullOrEmpty(email.Bcc))
            message.Bcc.Add(email.Bcc);
 
         if (!string.IsNullOrEmpty(this.ReplyToAddress))
             message.ReplyTo = new MailAddress(this.ReplyToAddress);
 
         if (!string.IsNullOrEmpty(email.Subject))
            message.Subject = email.Subject;
 
         if (!string.IsNullOrEmpty(email.Body))
            message.Body = email.Body;
 
         mail.Host = this.CentralAdminOutboundServerAddress;
         mail.Send(message);
      }
   );
}
Create a Live Meeting ‘Meet Now’ link in your email signature

Wouldn’t you like to be able to hold an impromptu Live Meeting with your co-workers or clients by simply saying to them: “Click on my Meet Now link.”

Sample email signature:

Mark Wagner | Microsoft | Services | Senior Consultant II | LiveMeeting: Meet Now 

Note: The Meet Now link above is a fake hyperlink since this is being posted on the Internet. :)

 

Why create a ‘Meet Now’ link in your email signature?

Having to schedule an impromptu Live Meeting and pass out the login code and/or custom link/URL, although it is pretty easy, it still takes longer than just telling your client/attendees to “Click on my Meet Now link.”  Being able to use Live Meeting for an unplanned meeting is a great resource to have.  A Meet Now URL will always be the same since you can only have one Meet Now meeting at a time.  Additionally, this URL can be posted on your internal My Site or placed in your email profile for easy access by your co-workers or clients.

Is it secure?

It sure is.  The ‘Meet Now’ feature has existed in Live Meeting for quite some time now.  As long as you configure it as I have noted below, you have the necessary control measure to safely and securely share your Meet Now link.

Configuring Your Personal ‘Meet Now’ Signature Link:

The link in your email needs to be the Meeting Lobby URL. The URL can be found on your My Home page on the Live Meeting web site – after you have logged in.  It will look something like:

https://www###.livemeeting.com/cc/microsoft/meet/YOUR-LOGIN-NAME

Configuring Your Live Meeting Account:

  1. Login to the Live Meeting web site. I’m not sure what your URL is, but it will look something like this:
    https://www###.livemeeting.com/cc/YOUR-COMPANY
  2. Click on Meet Now Details link.
  3. Click on the Meet Now Options link.
  4. Enable the Meeting Lobby option. This will allow users to connect and wait in the lobby area. You will have to manually grant them access to your meeting when they arrive in the lobby. This prevents anyone from joining your meeting at anytime, such as the wrong clients. Although, I can say this has not been a problem for me. 

Holding a ‘Meet Now’ Live Meeting:

  • Attendees: To hold a Live Meeting, have your meeting attendees simply click on the Meet Now link in any of your past emails, or as saved link somewhere. Once They will be waiting in the lobby until you join the Live Meeting and grant them access.
  • You: As the presenter, you can join your Meet Now live meeting a few different ways.
    1. By logging into the Live Meeting web site using your Meet Now URL, which will look something like:
      https://www###.livemeeting.com/cc/microsoft/meetNow
    2. By logging into the Live Meeting web site using your standard Live Meeting login page, and then clicking the Meet Now link. This is effectively the same as option number 1.
    3. By configuring your Live Meeting rich client Meet Now button. I will need to dig into this a bit more because I had to manually build the URL to get this to work. But, it is handy to be able to just click on your Live Meeting rich client application and click the Meet Now button. It’s a little faster and direct.

Note: If there are attendees I want to be presenters, I always have them join just like any other attendee. Once they are in the meeting I promote them to a presenter. Keep in mind that once you do this they will be able to see your presenter password in the Meeting Details window, if they look for it.

Logging to the SharePoint Log Files

Thanks to Brad Younge for sharing this a while back.  Below is an example on how to write to the SharePoint log files (located in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOGS folder).

catch(Exception e)
{
   Microsoft.Office.Server.Diagnostics.PortalLog.LogString("Exception: {0} - {1}", e.Message, e.StackTrace);
}

You’ll likely want to prefix your log entries with a date and time stamp.

How To SysPrep Your Virtual PC/Virtual Server Images

(Something that anyone who uses Virtual Server or Virtual PC should know.)

Overview

System administrators and software developers, especially those who are developing SharePoint solutions, often develop or test using virtual machines, either Virtual PC 2007 or Virtual Server 2005 R2.  Creating new virtual machines can be a time consuming effort; one we would all like to prevent from having to do every time we need a new virtual machine.  The great thing is that you can save all the time it takes to install Windows and the latest Windows Updates if you SysPrep a virtual machine.

What Is SysPrep?

SysPrep is a tool that allows you to prepare or “prep” a machine with the operating system along with any software you wish was pre-installed and pre-configured.  Once a machine is SysPrep’d, you have a new virtual machine that has the Windows operating system along with any additional software or features you want, such as IIS, pre-installed and pre-configured.  SysPrep allows you to create your perfect system configuration packaged so that you can have a new virtual machine up and running in just minutes.  And, it is available for both Windows Server 2003 and Windows XP.

Where Is SysPrep?

The SysPrep tool is located in a separate download from Microsoft called the System Preparation tool for Windows Server 2003 Service Pack 2 Deployment.

How To SysPrep

Building Your Virtual Machine Image

  1. Install your OS.  Windows Server 2003 R2 SP2 (or latest service pack), or Windows XP, or Vista.
    Note: I have not personally tried to SysPrep a Vista machine yet.
  2. Do NOT join the machine to a domain, at least not yet. (so you can leave the Admin password blank)
  3. Reset the Administrator password to blank.
  4. Get the latest Windows Updates.  Reboot and get latest again until there are no more required updates.
  5. Antivirus (Yes, your virtual machines should have antivirus software installed.)
  6. BGInfo (optional.  Just a tool I like to use that provides system information on the desktop background.)
  7. Daemon Tools CD Emulator.  (optional.  Just a tool I like to use to access ISO images.)
  8. Install the latest VM Additions.  (optional, but you will likely want to install this.  This comes with your Virtual PC and Virtual Server.)
  9. .NET Framework 3.5 SP1.  (optional.  This will include the latest .NET Framework for 1.1, 2.0, and 3.0.)
  10. Activate the Windows license (if you want to prevent having to re-activate Windows for each new virtual machine you create.)

Preparing to SysPrep: Creating a SysPrep.inf File

Before you can SysPrep you virtual machine, you need to create a SysPrep.inf configuration file.  This file contains the information about your machine.  It will also prevent you from having to enter you CD Key each time you create a new virtual machine from you SysPrep’d image.  Below is a sample of the SysPrep.inf file that you need to create.  This file configures the SysPrep process and automates boot up process.

  1. On your virtual machine, create a folder SysPrep at the root of your C: drive (C:\SysPrep).
  2. Copy the following text into a text file named SysPrep.inf.
  3. Enter the correct values for the following keys:
    1. TimeZone – the value of 10 is MST.  You may want to change this to your local time zone, but it is not required to do so.
    2. OEMDuplicatorsting – this should contain the name of the operating system you have installed on your virtual machine.
    3. FullName – your name, the name you would enter if you were installing Windows.
    4. OrgName – the name of your company, or blank.
    5. ProductKey – Your product key (CD key) license.

Sample SysPrep.inf file:

;SetupMgrTag
[GuiUnattended]
    TimeZone=10
    OEMSkipRegional=1
    OemSkipWelcome=1
    EncryptedAdminPassword=NO
    OEMDuplicatorstring="Windows Server 2003 R2 Standard"

[Identification]
    JoinWorkgroup=WORKGROUP

[Networking]
    InstallDefaultComponents=Yes

[LicenseFilePrintData]
    AutoMode=PerServer
    AutoUsers=50

[Unattended]
    OemSkipEula=Yes
    InstallFilesPath=C:\sysprep\i386

[UserData]
    FullName="YOUR NAME HERE like Mark Wagner"
    OrgName="YOUR COMPANY NAME HERE like Contoso"
    ProductKey=YOUR-PRODUCT-KEY-HERE

[SetupMgr]
    DistFolder=C:\sysprep\i386
    DistShare=windist

Your SysPrep.inf configuration file is now ready to be used.

 

SysPrep-ing your Virtual Machine

SysPrep-ing your virtual machine takes just a minute or two.  Most of the time is simply shutting down your virtual machine.  Important: do not start this virtual machine back up or it will un-SysPrep your machine.  If this does happen, you can simply go through these steps below to SysPrep you virtual machine again.

  1. On your virtual machine, in the C:\SysPrep folder, run SysPrep.exe.
  2. Check the “Don't reset grace period for activation” option.
  3. Make sure Shutdown mode is Shut down.
  4. Click the Reseal button to shutdown and package.
  5. Click OK to generate new SID's.
  6. Your virtual machine will now shut down and be SysPrep’d.
  7. You now have a virtual image that is SysPrep’d, but not ready to be used.
  8. Before you use this image, you will need to make a backup copy of your virtual machine image files.  This will allow you to always have a SysPrep’d virtual machine ready and waiting.
  9. Backup your SysPrep’d virtual machine image files (.vhd, .vmc), and rename them to something you can easily understand and that describes what your image contains.  For example:
    1. Windows Server 2003 R2 SP2 SysPrep.vmc
    2. Windows Server 2003 R2 SP2 SysPrep.vhd
  10. You now have Your virtual machine SysPrep’d.  You can now use this image to quickly create a new virtual machine in minutes, with a new machine name and new unique System ID (SID) each time you use it.

Using Your SysPrep’d Image to Create a New Virtual Machine

Now, creating a new virtual machine will only take just a couple minutes.

  1. First, you need to copy your SysPrep’d image to a new name and to a new location where you will use this new virtual machine.  Copy your SysPrep’d image files (.vmc & .vhd) to a new location where you want your new virtual machine file to reside.
  2. Rename them to a new, appropriate name.  For example, if you are going to create a SharePoint server you might name them something like:
    1. MySharePoint2007.vmc
    2. MySharePoint2007.vhd
  3. Add this new virtual machine to you Virtual PC or Virtual Server; which ever you are using;
  4. Edit the configuration and make sure the virtual hard drive (VHD) is pointing to your new .vhd file.  In this example, the MySharePoint2007.vhd file.
  5. Configure any other items such as memory allocation and network cards as necessary.
  6. Start the virtual machine.
  7. You will receive a few prompts such as the name for you new machine.
  8. If you wish, you can now join you virtual machine to a domain.

SysPrep is a must have time-saving tool for anyone who uses Virtual PC and/or Virtual Server.

Unauthorized (401.1) Exception calling Web Services in SharePoint

After upgrading to .NET Framework 3.5 Service Pack 1 on my SharePoint web servers I began to get the following Unauthorized exception.

Type: WebException, Exception Message: The request failed with HTTP status 401: Unauthorized.

This error really has nothing to do with SharePoint, and is really just an IIS web services related item.  This problem is due to an added bit of security included in the .NET Framework 3.5 Service Pack 1.  Here is the Microsoft KB article explaining the issue and how to work around the problem.  This Microsoft article refers to the problem coming after applying other service packs for Windows XP and Server 2003, but .NET Framework 3.5 Service Pack 1 is also now using this same bit of added security - the loopback check.

You will likely not encounter this problem on a single web server configuration and if you are using the server name to access the web site.

However, most enterprise SharePoint farms consist of at least two web servers that are load balanced.  This is where the problem exists.

Likely Cause:

  • You are calling your web services from your web servers using the load-balanced URL, not the server name.

This isn't a bug.  There was a security fix built into the Windows networking stack that prevents a machine name that resolves to the loopback address from accepting a connection unless that machine name matches the NETBIOS name.

One option is to use the server name instead of the load balanced IP.  This should remedy the problem.  However, the standard method to apply configuration changes across a SharePoint farm is via SharePoint solution files.  This usually requires the configuration entries to be the same across all the web servers in the SharePoint farm, and using the load balanced URL is likely the most appropriate.

Suggested configuration changes to resolve this:

  • Add the DisableLoopbackCheck registry entry discussed in this Microsoft KB article.  Note: you will need to reboot your server before the DisableLoopbackCheck takes effect.
  • Be sure to add your load balanced host name for your web farm to the Hosts file on each front end web server.  Use the loop-back IP address (127.0.0.1).  This will ensure that each web server looks at itself to access the web services preventing any trips back out to the load-balancer - and possibly calling the web service another web server in the farm.  This will be much less efficient.
    • If this problem appeared to be inconsistent (sometimes erroring, sometime successful), this is most likely due having multiple web servers.  The call to the web service will be successful if by chance the load balance redirected the call to the same (self) web server to access the web service.  It will fail when trying to call across to a different web server.

References:

I'm mentioned (twice) in an MSDN Magazine article - SWEET!
It is an exciting moment to have two articles on my blog discussed and referenced in the May 2008 edition of MSDN Magazine.  Thanks to Ethan Wilansky for a great article in MSDN Magazine, and for making this happen!
 
MSDN Magazine - May 2008 Cover
Here is the link to the MSDN Magazine article:
Here are the links to two of my blog articles that are referenced in this MSDN Magazine article:
Also, Shawn Feldman, a coworker, was also mentioned for his terrific work in deploying SQL Reports.  Here is a link to Shawn's blog article.
 
Apply a Theme to all sub sites in SharePoint 2007
Apply a Theme to all sub sites:
(works for MOSS 2007 only, not WSS 3.0)
  1. Change the top site to the theme of your choice using the normal method in Site Actions > Site Settings > Site Theme.
  2. Navigate to the top site to see the newly applied theme.
  3. View the HTML source of the SharePoint page using the theme you want.
  4. Look for a link tag containing the .css file for the applied theme.  It will look something like this:
    <link rel="stylesheet" type="text/css" id="onetidThemeCSS" href="/apps/afe/_themes/Belltown/Bell1011-65001.css?rev=12%2E0%2E0%2E4518"/>
  5. Copy the href value to your clipboard or to a text file if you like.  It should look something like:
    /apps/afe/_themes/Belltown/Bell1011-65001.css
  6. On your top level site, go to the Site Actions > Site Settings > Master Page screen.
  7. Scroll to the bottom where the Alternate CSS URL section is.  Select the "Specify a CSS file..." option.
  8. Paste the path copied from the href above into the text box.
  9. Check the Reset all sub-sites to inherit this alternate CSS URL option.
  10. Click OK.
  11. Navigate to your sub-sites and verify the theme has been applied.
SPSecurityTrimmedControl: Conditionally display contents by security
The SPSecurityTrimmedControl control will conditionally render the contents of this control to the current user only if the current user has access to the permission defined in the PermissionString.  The content can be any HTML code or control you like.  The PermissionString attribute defines the permission required to view the contents.  These Permissions are the same base values that are used in various combinations to the define the default Permission Levels that are created with each new site collection such as Design, Contribute, Read, etc...  You can also create your own custom Permission Levels for use in configuring your SharePoint security.  But remember, the PermissionString attribute can only be supplied valid Permission values, not Permission Levels.  There are 33 base SharePoint Permissions (Permission levels and permissions) of which any of these can be used.
This is a terrific control for use with your custom master pages and even with any custom SharePoint .ASPX pages you are hosting in SharePoint.
 
Attributes:
  • PermissionString: (required)
    Defines the permission values required to render the contents.
  • PermissionContext (optional):
    Enumeration Values:
    - PermissionContext.CurrentFolder
    - PermissionContext.CurrentItem
    - PermissionContext.CurrentList
    - PermissionContext.CurrentSite
    - PermissionContext.RootSite
  • PermissionMode (optional):
    Allows you to define whether All permissions are required or Any permission is required to render contents.
    Enumeration Values:
    - PermissionMode.All
    - PermissionMode.Any
Sample code:

<Sharepoint:SPSecurityTrimmedControl runat="server" PermissionsString="AddAndCustomizePages">

You can place any text or HTMl in this section. Only users having the AddAndCustomizePages permission will see this.

</SharePoint:SPSecurityTrimmedControl>

If you need to, you can even create your own Security Trimmer as shown here.
http://msdn2.microsoft.com/en-us/library/aa981236.aspx

Another method worth noting is the RightsSensitiveVisibilityHelper.UserHasRights method.
https://msdn2.microsoft.com/en-us/library/ms465624.aspx

References:

How To: Create a SharePoint Solution for an InfoPath Form
Mark Wagner
 
Summary
This post discusses how you can create a SharePoint solution package to deploy an InfoPath form to your SharePoint 2007 farm.  No coding required.
 
Downloads
 
Overview
InfoPath forms are normally deployed manually using the Manage Form Templates administration tool in Central Administration.  These forms can also be deployed using the STSADM command.  Although both of these methods work perfectly well, they are not always the desired method.
 
Since the release of SharePoint 2007/3.0 there have been a few new utilities that provide an improved and simplified deployment experience.  I have personally created installer classes for use with a packaged .msi file to simplify the process of deploying many SharePoint solution packages at once using the SharePoint 2007 object model.  The problem is that I have been unable to deploy an InfoPath form to SharePoint via the object model.

The result is a quick and simple solution to create your InfoPath form solution packages…   Let SharePoint do it for you.
 
Concept
If you have ever deployed an InfoPath form to SharePoint 2007, you may have also noticed that a new solution package appears in the Solution Management screen.  The name of this mysterious new solution begins with “form-“, followed by something that probably resembles the name of the InfoPath form you installed using the Manage Form Templates administration tool.  Chances are you probably assumed it had something to do with your form but just weren’t sure.
 
The new solution named “form-SOMETHING-NNN” is actually a solution package created by your SharePoint server that contains your new InfoPath form.  This allows your InfoPath form to be deployed and retracted to the web applications of your choice just like any other solution.
 
So, wouldn’t it be nice to see what that package looks like?  Heck, it would be even better if you could use that package to redeploy your form (as a solution package, not as an InfoPath .xsn file) to other SharePoint environments such as your Integration Testing, User Testing, and eventually on to your production environment.  The only question remaining is how do you export that solution package out of your SharePoint farm?
 
This is why I created the SharePoint Solution Exporter tool.
 
SharePoint Solution Exporter
The SharePoint Solution Exporter is a very simple little tool that allows you to export and save any solution installed on your farm to your local disk.  Once you have exported your solution (.wsp) file you can rename it to a more appropriate solution name for easy and clear identification; and you can take that solution and deploy it to another farm.  Here is what the SharePoint Solution Exporter tool looks like:
 
SharePoint Solution Exporter screen
 
You must run this tool locally on your SharePoint web server.  To export a solution package:
  1. Enter the URL to your web server and click the Go button.
  2. A list of installed solutions will appear in the list body.
  3. Select the solution of your choice.
  4. Click the Download Solution File and specify name of your solution file in the Save As dialog.

I hope you find this tool as helpful as I have.

Note: For those of you interested in how to create a Sharepoint solution package from scratch using Visual Studio, I hope to post an article soon on how to acomplish that as well.

1 - 10 Next

 ‭(Hidden)‬ Admin Links