.NET 3.5 SP1 – Action Attribute in the Form Element of an ASP.NET Page

I was recently brought into a SharePoint project to help fix some bugs and generally be there as an extra resource while the team prepared for various “go live” dates.  One issue we were having was a failure to post form data to another web site for an automated login of sorts.  From within SharePoint, a link was created that would direct the user to an ASP.NET page, gather information and manipulate it from the user’s profile, determine which site the user wanted to go to and then submit the data to the site for an automatic login.  Easy enough, right?  Except it had one catch – when the “redirector” page submitted the form data to the site, it wouldn’t post to the target site.  Now, this problem occurred when the necessary files were deployed to the dev environment.  It worked very well on our individual development machines.  Why was this happening?

After some research, I found a couple articles here and here that outline an issue that is solved by installing .NET 3.5 SP1.  From my understanding, from .NET 1.1 through 3.5, if you put a URL value in the Action attribute of the ASP.NET form, the code was ignored by the framework and posted back to itself.  Unlike the days of classic ASP where you could define the POST event, .NET adopted the model of single post back.  This means that regardless of the URL you specify in the Action attribute of the form tag, the page will always post back to itself, rendering the Action attribute useless and dead.  You’d have to use the Response.Redirect method or the Server.Transfer method (under certain circumstances) to get to another page.  Unfortunately, this didn’t actually post the data in the form – it just redirected the user to the new page, without logging the user in.  (Server.Transfer would probably work if you were posting to a site on the same server, but in this case we were not.)

<form id="form1" runat="server" action="http://www.myurl.com"></form>

With the release and implementation of SP1 for .NET 3.5, this issue has been addressed.  You can now enter a URL to post to in the Action attribute and then use the submit() from within a RegisterStartupScript call to submit the form data to the target URL.

ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myScript", "document.forms.form1.submit();", true);

So, if you ever have to post data to another web site for anything, this is an easy method.  Just make sure the server the code is running on has .NET 3.5 SP1 installed and you shouldn’t have the problem we did.

Custom Client Installation Experience for Silverlight 2 SharePoint Web Part

I was recently tasked with creating a demonstration for a company that involved creating a video player to place into a SharePoint Web Part.  The end result turned out to be very nice and was based upon the Silverlight SharePoint Blueprint project on CodePlex.  I did modify the player to add functionality for play, pause, stop and volume controls, as well as a video slider I found that works very well.  I’d like to compliment the folks on the Blueprint team for their results – it’s really a great starting point for a customized Silverlight and SharePoint solution.  Just a note – I believe the Blueprint still uses the Beta 2 version of Silverlight, so be aware of the break-changes relating to that if you decide to implement any of the controls.

After the player was created, I started thinking about the situation that would arise when the user didn’t have Silverlight installed on their machine.  We all know the standard image and link that is displayed when this is the case.  Tim Heuer has a great video on how to customize the installation experience for pure Silverlight applications, but I wondered how that would apply to a SharePoint Web Part.  After scouring the internet and a couple of emails to Tim regarding this caveat, I figured it out.  Of course, like most things that take me a while to figure out, it’s actually quite simple. ":)

What the web part was doing was declaring an ASP.NET Silverlight control and setting the properties to it in the Web Part’s CreateChildControls overridden method.  The basic, necessary attributes of the control were then set (ID, Version and Source in this case) , excluding the PluginNotInstalledTemplate property.  Without setting the content of this property, the default image/link appears for the client by default.  Example is below:

   1: // instantiation of the silverlight control
   2: System.Web.UI.SilverlightControls.Silverlight silverlightControl = new System.Web.UI.SilverlightControls.Silverlight();
   3: silverlightControl.ID = "MediaViewerBeta2";
   4: silverlightControl.MinimumVersion = "2.0.30523";
   5: silverlightControl.Source = "/ClientBin/XAP/SLSP_MediaViewer.xap";
   6:  
   7: // Define the width and height based on the webpart height
   8: Unit height = new Unit(425);
   9: Unit width = new Unit(600);
  10: if (!this.Height.IsEmpty)
  11:     height = this.Height;
  12: silverlightControl.Width = width;
  13: silverlightControl.Height = height;

To set this property, I overrode the Silverlight control class and declared a new class called PluginTemplate that inherits from the iTemplate interface.  The PluginNotInstalledTemplate property type is of iTemplate.  Within the new PluginTemplate class, I created the InstantiateIn method to set the custom installation verbiage within an asp.net label control via a StringBuilder.  Obviously, this can be done in different ways depending on the experience you want the user to have.  I just chose this for simplicity sake – it may require some jazzing up later.  The two new classes are below:

   1: /// <summary>
   2: /// Custom control class representing the SilverlightControl - will be used to provide a custom installation experience for the client if
   3: /// Silverlight is not installed.
   4: /// </summary>
   5:     public class SilverlightBase : System.Web.UI.SilverlightControls.Silverlight
   6:     {
   7:         public SilverlightBase() 
   8:         {
   9:             base.PluginNotInstalledTemplate = new PlugInTemplate(); 
  10:         }
  11:     }
  12:  
  13:     /// <summary>
  14:     /// ITemplate class to add to the custom Silverlight control
  15:     /// </summary>
  16:     public class PlugInTemplate: ITemplate
  17:     {
  18:         #region ITemplate Members
  19:  
  20:         public void InstantiateIn(Control container) 
  21:         {
  22:             StringBuilder str = new StringBuilder();
  23:             str.Append("<h2>Get Microsoft Silverlight 2</h2>");
  24:             str.Append("<p>This application requires Microsoft Silverlight 2 to " + 
  25:             "provide a rich integrated media experience. Silverlight is a small, " + 
  26:             "safe, cross-platform browser plugin created and supported by Microsoft.</p>");
  27:  
  28:             str.Append("<p><div style='position:absolute;'>" + 
  29:             "<a href='http://go.microsoft.com/fwlink/?LinkID=124807' " + 
  30:             "style='text-decoration: none;'><img src='http://go.microsoft.com/fwlink/?LinkId=108181' " + 
  31:             "alt='Get Microsoft Silverlight' style='border-style: none'/></div></p>");
  32:  
  33:             System.Web.UI.WebControls.Label txt = new System.Web.UI.WebControls.Label();
  34:             txt.ID = "lblMess";
  35:             txt.Text = str.ToString();
  36:             
  37:             container.Controls.Add(txt);
  38:         }
  39:  
  40:         #endregion
  41:     }
  42: }

With the new Silverlight control class built with the new instance of the PluginNotinstalledTemplate, I changed the declared instance of the Silverlight control in the Web Part from the System control to the custom control.  Now the installation experience for the client is customized according to the content of the PluginTemplate class.  The resulting display is below:

Result 

Not a totally exciting result, but it is better than just the image, no?  Hope this helps someone!

-G

RMSUG Presentation – Workflow References, 11/18/08

If you attended the Rocky Mountain SharePoint User Group meeting on the 18th, I thank you for sitting through my presentation on Workflow. Hopefully, you found it informative. (Or entertaining at the very least!) The following is a list of 10 sites and materials that helped me in preparing for this presentation and can be used as general references for Workflow in a SharePoint environment and beyond, with an emphasis on custom workflows for SharePoint.

  1. SharePoint Workflow Development in VS – This is the first of a series of walkthroughs written by Eilene Hao for creating workflows with Visual Studio.

    http://blogs.msdn.com/sharepoint/archive/2006/11/18/developing-workflows-in-vs-part-1-workflow-objects-and-a-crash-course-on-mechanics.aspx

  2. Introduction to Workflows – One good basic introduction into Workflows in an Office environment

    http://office.microsoft.com/en-us/sharepointserver/HA101544241033.aspx

  3. Information on Translation Workflows

    http://office.microsoft.com/en-us/sharepointserver/HA101544301033.aspx

  4. Writing Workflows in VS 2005

    http://blah.winsmarts.com/2007-8-Writing_SharePoint_Workflows_in_VS2005_-_Crawl_Walk_Run.aspx

  5. How to Debug your Windows SharePoint Services Workflow

    http://msdn.microsoft.com/en-us/library/ms455354.aspx

  6. SharePoint Advanced Asynchronous Workflow Messaging – Video presenting advance techniques for creating workflows with asynchronous functionality

    http://channel9.msdn.com/pdc2008/BB47/

  7. Delete Files with Workflow Using Duration

    http://www.sharepointblogs.com/holliday/archive/2007/07/26/delete-files-using-workflow-using-duration.aspx

  8. Deactivate and Delete a Workflow Activity from SharePoint

    http://russellmccloy.blogspot.com/2008/01/deactivate-and-delete-workflow-feature.html

  9. Developer Introduction to Workflows for Windows SharePoint Services 3.0 and SharePoint Server 2007

    http://msdn.microsoft.com/en-us/library/aa830816.aspx

  10. K2 Underground – Third party company specializing in providing workflow engines for SharePoint and beyond

    http://www.k2underground.com/

Hello to Analysts International

I’ve now been at Analysts for two weeks and love it! I should be starting my first project sometime mid September, from what I hear. In the meantime, I’ve been asked to learn about and come up with a presentation on SharePoint Workflow. I’ve done some research and have found a lot of great sites that have helped me learn about creating workflows in SharePoint. I’ve also purchased a couple books that have helped me create workflows in Visual Studio 2005 and 2008. Two in particular that have been open on my desk for the past couple weeks are Workflow in the 2007 Microsoft Office System by David Mann and Pro InfoPath 2007 by Philo Janus. Both have a great amount of information specific to workflow within the SharePoint framework and cover everything needed to create custom workflows in MOSS.

Suffice it to say, I’ve created test workflows in my little test environment and have found that creating them in VS 2008 and deploying them from it is much easier than VS 2005. The feature and workflow XML files are already created and filled in with what was typically in the snippet provided for VS 2005. As well, all you need to deploy workflows in VS 2008 is to right click the workflow project and select Deploy, instead of the two or three steps needed in VS 2005. Very nice.

One thing I did learn to do while creating my demo workflow is to make sure you create only one or two activities, compile and test them, then add additional activities. This may go without saying, but it’s MUCH easier to debug a workflow that has only a couple of new activities than it is to go through part of the workflow and finally find the issue. Yes, I learned this the hard way.

I’m thinking in an upcoming blog of creating a workflow for demonstration purpose through VS 2008. You’ll possibly see that soon.

SharePoint Certified!

I have passed the MCTS – SharePoint Configuration exam and am now an MCP! Yipee! It wasn’t as hard as I thought, although I did go overboard on the studying, which isn’t that bad. I definitely learned a lot from the experience and the studying, so I believe it was worthwhile. It doesn’t look bad on a resume either.

I’ve set up a company GJDCorp to start the process of getting a consulting business up and running. I’m planning on working with Matt Passanante from SharePoint Experts in doing this. We’ve talked quite a bit and I’m excited to start.

Follow

Get every new post delivered to your Inbox.