SharePoint Scenario Framework

August 25, 2011

While reading my usual list of blogs I came across an article on nothingbutsharepoint by Waldek Mastykarz on SharePoint Scenario Framework. This is something I have never heard of before but after reading the article I can definitely see the use of it so wanted to spread the word.

Multi-page forms with the SharePoint Scenario Framework

Disco file location

August 16, 2011

During my time I have created and consumed numerous web services. There are quite a few good guides out there such this MSDN article but the one thing I always forget is where to run the disco tool from to generate the WSDL and Disco aspx pages.

The funny thing is there is a few different places you can find this tool they are:

  1. In the Microsoft SDKs folder in Program files, usually in the bin folder. At the time of writing this I am using Windows Server 2008 and there are two options either v6.0A or V7.0A and in my case disco.exe is in the bin folder of V7.0A.
  2. This can also be accomplished using the Visual Studio command prompt. Simply open it and type disco and you will be asked for the appropriate options.
  3. I have also found on some servers there is also a copy at C:\windows\Microsoft .NET\Framework\Verisonx.x.x.x\ although this is not always the case. This could have been added when additional software has already been installed.

Regardless of how often I have done this I still always forget so hopefully this will help me remember but also help anyone else who is also as forgetful as me Smile

Creating installation package for Windows Forms Applications

August 5, 2011

Over the years I have created numerous Windows Forms Applications for a variety of purposes. Normally this is for my own use or for use by an IT team but on a recent project I was developing a Windows Forms Application which is to be used by regular Joe Blogs end users. This meant I needed to provide an installer to ensure all the prerequisites were installed i.e. .Net framework, etc. While it is not something I have had to do a lot of I have created a few installers in my time, however most of them have used the OOTB Setup Project template from Visual Studio.

On this project I am still using the OOTB Setup Project, however I have also had to capture some additional parameters during the installation such as the URL of the web service to connect to. I knew this would be possible but I had no idea what would be involved but after some research I was able to find an excellent MSDN article on Using a Custom Action to Display a Message at Installation. While the idea is slightly different the principle is the same and you can easily adjust this. In my case I capture the web service URL and update the settings file with the URL supplied. I found a good article which details the steps required to update the configuration file. My code is slightly different in that it is within the custom installer class so I have included this below as well.

Code in Customer Installer Class

Code Snippet
  1. public override void Install(System.Collections.IDictionary stateSaver)
  2.         {
  3.             base.Install(stateSaver);
  4.             try
  5.             {
  6.                 string webserviceURL = Context.Parameters["PARAMETER1"];
  8.                 Configuration config = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
  9.                 ApplicationSettingsGroup group = config.GetSectionGroup("applicationSettings") as ApplicationSettingsGroup;
  10.                 ClientSettingsSection settingsSection = group.Sections["Applications.Properties.Settings"] as ClientSettingsSection;
  11.                 SettingElement webServiceSetting = settingsSection.Settings.Get("SETTINGNAME");
  12.                 webServiceSetting.Value.ValueXml.InnerText = webserviceURL;
  13.                 config.Save(ConfigurationSaveMode.Full, true);
  14.             }
  15.             finally
  16.             {
  17.                 base.Dispose();
  18.             }
  19.         }

DataGridView CellEnter event fires multiple times

August 4, 2011

When working on a Windows Forms Application I had a DataGridView and I wanted to update some textboxes at the bottom of the form when the user selected a particular row/cell. I looked at the different DataGridView events available and decided the best option to cover users clicking on a cell and them navigating around the DataGridView using the up and down arrows was the CellEnter event.

Everything seemed to be working fine but I was occasionally getting some strange result or errors so I decided to spend some time debugging to try and identify the issue. What I found was even if I was not clicking on the DataGridView certain other actions caused the CellEnter event to fire also when I first clicked on an a row/cell after loading the form the event fired twice. This was extremely problematic in my case as I was doing some additional processing on a background worker thread so these miscellaneous events being fired resulted in unexpected results and the occasion exception as the background worker thread was already in the middle of processing another request.

Reading up on the CellEnter event it mentions that the event may occur twice if the DataGridView didn’t have input focus. Thinking about it this made sense and related to the issue I was having where the event was indeed firing twice. What must be happening is when a user clicks on a cell the focus must first be set on the DataGridView and when this happens it must act like it is selecting the first cell hence every time I was debugging the first time around the column and row indexed were both 0. I was able to get around this by adding the code below to the top of the CellEnter event. This way if the DataGridView wasn’t Focused I could exist the event without processing.

Code Snippet
  1. if (!DgvData.Focused)
  2.             {
  3.                 return;
  4.             }


This seemed to work but it meant when I loaded the DataGridView first time around the additional information at the bottom of my form was not filled in as technically the form still didn’t have input focus. I was able to get around this by manually setting the focus on the DataGridView after I assigned my data source. This would then trigger the CellEnter event where DgvData.Focused would now be true so it would continue and do the additional processing I wanted.

Code Snippet
  1. //binding causes the cell enter event to fire.
  2.                     DgvData.DataSource = calls;                    
  3.                     //show calls tab. This causes the cell enter event to fire as well.
  4.                     ShowTab(TpCallPlans);
  6.                     DgvData.Focus();


The other issue I was having was the CellEnter event was firing when I was not touching the DataGridView. In my form I had multiple tabs and the DataGridView was on the first one. I have several buttons on the form that show or hide the relevant tabs but what I noticed was that removing a tab from the TabControl also triggered the CellEnter event. The code below shows the function I was using to only show the appropriate tab and when stepping through the code line 11, actually removing the tab from the TabControl, caused the CellEnter event to fire. Obviously this was not what I was expecting and was leading to incorrect data on certain sections of the form. What I found was the same fixed I used above also corrected this issue as while the event still fired the DataGridView didn’t have input focus so it simply existed the method.

Code Snippet
  1. /// <summary>
  2.         /// Method to hide all tabs except the one supplied
  3.         /// </summary>
  4.         /// <param name="tpToShow">A TabPage object of the tab we want to show</param>
  5.         private void ShowTab(TabPage tpToShow)
  6.         {
  7.             foreach (TabPage tp in TbOptions.TabPages)
  8.             {
  9.                 if (!tp.Name.Equals(tpToShow.Name, StringComparison.CurrentCultureIgnoreCase))
  10.                 {
  11.                     TbOptions.TabPages.Remove(tp);
  12.                 }
  14.                 if (TbOptions.TabPages.Count == 0)
  15.                 {
  16.                     TbOptions.TabPages.Add(tpToShow);
  17.                 }
  19.             }
  20.         }


Hopefully this can help other people encountering the same issue as it took me a while to work out why this was happening and how to resolve it.

%d bloggers like this: