Adding debug capability to custom STSADM commands for MOSS and WSSv3

by michaellotter 30. January 2008 21:29

Since my InfoPath 2007/InfoPath Forms Services project has ended you will start to see more posts on my blog about other SharePoint related things and less about InfoPath 2007/InfoPath Forms Services.  My new project is currently in NYC and it will last until March 31st.  The project is a 100% different than my last project and I'm sure I'll be learning a lot of new things for this blog.  This post is from another project that I'm doing on the side and I just wanted to share a small piece of it with everyone.  If you're attending the South Florida Code Camp then you will get the full picture of everything if you attend my second session "Creating custom commands for STSADM with C#".  Later in February I'll also do a couple of posts on my blog to explain more of the details if you can't attend the code camp.

Ok, enough of my babbling and now to the details of the post.  A few weeks ago I needed to extend the STSADM utility to do a couple of things that it current doesn't have commands for or at least I couldn't find them.  When I built the initial project and deployed the assembly and started to test everything I ran into problems with the code (I wish I could write perfect code).  I struggled trying to get all the code working correctly without having the capability of debugging the code while it ran.  I could have done the old "Console.WriteLine" but I didn't want to go through this approach because I was tired and it would have been way too tedious for me.  This was really frustrating and I decided to figure out what needed to be done to make debugging an option.  I did a little searching but couldn't find anything that helped me (probably not using the correct search words).  When I started to really think about the whole scenario it reminded me about onetime I had to write a Windows Service and I ran into the same type of problem.  To solve that problem I added the "System.Diagnostics.Debugger.Launch" command to my code so I could debug my Windows Service.  So I figured what the heck and I added it to my code and everything complied without a problem.  I deployed the assembly and ran my custom STSADM command and then the Visual Studio Just-In-Time Debugger window popped up as expected.

Since I had already had the code project open I just highlighted that line and clicked the "Yes" button to debug my code.  If I didn't have the code project already open then I would click "New instance of Visual Studio 2005" and the code would automatically loaded into Visual Studio 2005.  Even if you don't have the code project on the server but have the "obj" folder and all its content then debugging is still possible (at least from my experience it is).  When the debugger is ready your code will have a green arrow next to it like the image below.

 

At this point I usually hit the F10 key and then everything changes to the correct colors and everything works as normal. 

When I got the debugging working with my code it was a lot simpler to see what was wrong with the code.  Then I started to test all the different options for my custom command and the debugger launching all the time started to drive me nuts.  I guess everything is not perfect but then it dawned on me what if I just add a debug option to the command string.  Something like "-debug" and if that's present then launch the debugger.  I thought it could work so I added the extra code to my project to make it happen and compiled everything and moved the assembly into the GAC again.

 

I went and tried my command again without the debug option and everything ran like normal and then for the big test I add the debug option and the debugger launched and everything worked just as I hoped.  Now I have complete control when the debugger will launch and I will no longer have the nuisance of the debugger launching every time. 

This was a great learning experience for me in many different ways but it really helped me open my eyes on making things more functional and user friendly by taking a little extra time to think about what could be done.

Cheers

Tags:

Microsoft Visual Studio 2005 | STSADM

How to accidently add an assembly to InfoPath 2007 Form and how to remove it

by michaellotter 27. January 2008 23:07

This is a really old post that never made it because I just totally forgot about it until I read Paul Galvin's post http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!609.entry and I thought it was still worth posting because it's such a common problem and most people don't know that it happens.

So here it goes;

The last few weeks I have learned so many things when working with Josh Medero (Jason Medero brother).  Josh has been helping me out with my InfoPath 2007/InfoPath Forms Services project and he has accidently done a couple of things that I've never done or seen before but that's totally cool because it has helped me learn new things about InfoPath 2007 and InfoPath Forms Services.  As you probably already know this post is about another thing that I learned today.

If you're a developer and have ever worked with InfoPath 2007 forms then you've probably have added a button to the form and have accidentally clicked the "Edit Form Code" button and launched Microsoft Visual Studio Tools for Applications (VSTA) and then closed it because you meant to click the "Rules" button.

When the VSTA window was closed I would have never have thought it would actually create anything and especially if nothing was saved.  For Josh it created an assembly for the form even though no code was added.  He never knew that an assembly was added to the form and I would have never known it but he was having other issues with his form and he sent it to me to open and preview. When I went to preview the form I got the following warning.

The reason that I got the warning was because I don't install VSTA on my laptop but VSTO instead.  After I say the warning message it started to get me wandering what was wrong.  First thing that I did was close InfoPath 2007 and then explored the XSN file and noticed it had a dll in it.  After I noticed this I opened the form backup and went into "Tools" -> "Form Options" and clicked "Programming" category.

The "Programming" category page shows that something was created and once I saw this I just clicked the "Remove Code" button to remove the unwanted assembly.  When I clicked the button the following pop-up came up and I clicked the "Yes" button to remove the code.

After I did these steps I no longer got the warning message when opening the form and Josh problems no longer existed either.  If you really don't plan to do coding in InfoPath with VSTA then I would suggest not to install VSTA that way this problem doesn't occur accidently.

Cheers

 

Tags:

InfoPath 2007

South Florida Code Camp now doing 2 sessions

by michaellotter 24. January 2008 13:29

Just wanted to let everybody know that I am now doing 2 sessions at the South Florida code camp and my second session title is "Creating custom commands for STSADM with C#".  The session goes into the details of extending the STSADM utility and how to debug the code.  The code being reviewed is currently being used in the real world.  I'm pretty excited about doing this session because it's something totally different from my normal subject.  Please come out to the code camp on February 2nd but remember you need to register first.   You can check out the agenda and register from the http://codecamp08.fladotnet.com/ website.

Cheers

Tags:

Public Speaking | Code Camp

Speaking at the South Florida Code Camp on February 2nd

by michaellotter 20. January 2008 23:57

That's right it's time for the South Florida Code Camp and I'll be down there giving a new session on InfoPath 2007 and Visual Studio 2008.  For this session I'm thinking about changing a couple of things around and doing some really new stuff that includes C# code for updating AD and XMLFormView control for displaying an InfoPath 2007 form.  I'm thinking that the InfoPath 2007 form will be a data entry form that allows users to update their AD information.  I've been thinking about this new presentation for a while and since Visual Studio 2008 was officially released I figured that I should also change up the InfoPath part.  I'm really excited about building the new code and presenting it and after the code camp is over I'll post it on my Code Camp and User Group page.

All the information about the South Florida Code Camp can be found on the http://codecamp08.fladotnet.com/ website.  From what I heard while at Philly Code Camp from other speakers this code camp is suppose to be as big as or bigger than the Philly Code Camp one.  To see what sessions are currently on tap checkout the agenda page http://codecamp08.fladotnet.com/agenda.aspx.  The code camp is going to have 12 different tracks and that means tons of sessions.  The "SharePoint/ Office" track already has my "InfoPath 2007 and Visual Studio 2008" session and "Utilizing Visual Studio 2008 capabilities for better SharePoint Development Part 1 and Part 2" sessions on tap.  In my opinion this track is already shaping up to be a killer track.

I'm really excited about this code camp and I'm glad to have the chance to speak at it and I hope to meet some new SharePoint colleagues there to.  Well I'm about all posted out for the night.  Hope to see some of you there.

Cheers

Tags:

InfoPath 2007 | Public Speaking | Code Camp | Microsoft Visual Studio 2008

Philly Code Camp was a blast

by michaellotter 20. January 2008 23:35

Last weekend was the Philly Code Camp and Nas and I had a blast with the other 375 people that attended the event.  The one day extravaganza featured 50 different speakers and in many sessions it was standing room only.  If you work with Microsoft technologies on the dev side and local to the area or in driving distance then I would definitely try to make it out to one of their other two code camps this year.  My InfoPath 2007 and Visual Studio 2008 session went really well I think and I really enjoyed myself.  I would like to thank David Mann for letting me speak and all the other people that put together this great event.

When at the Philly Code Camp I got to meet a couple other great SharePoint speakers.  After my session I got to speak with Susan Lennon (http://wss.lennontechnologies.com/blog/default.aspx) who did a session on "Using SharePoint Designer to Build a Dashboard-type View of Lists" and got to sit in on the session by Tony Testa (http://www.tonytestasworld.com/) called "AJAX in SharePoint".  Susan and I didn't have a long time to talk but she seemed to be a great person with some interesting experience with SharePoint 2007.  I'm hoping to have another chance to talk with her while out at Office Developer Conference in February.  Dave Mann did his session after mine and it was a great session on you guessed it Workflow and SharePoint.

As promised my presentation and code solutions are up on my Code Camp and User Group page and I just sent them to Philly Code Camp organizers and should be posted on their site shortly.  If anybody has any questions about the code please fill free to email at ml@(nospam)bandrsolutions.com

Cheers

Tags:

Public Speaking | Code Camp

You must choose a publish location that is different from the source Web application error message when trying to publish a web project with Visual Studio 2005

by michaellotter 20. January 2008 23:18

When living in the InfoPath and SharePoint world I sometimes don't really get to know how to use some tools that great until I get a stray project that forces me to do things that I normally wouldn't do on a day to day basis.  Recently I've had two projects like that and fortunately for me I've learned a bunch of new stuff that probably most developers learned years ago when the tools were first released.  This post is about me finally figuring out how to switch back from Visual Studio 2005 "IIS Web Server" debug mode to "Visual Studio Development Server" mode.  In Visual Studio 2005 web projects have this properties tab called "Web" and on it you can specify either to run debug from "Visual Studio Development Server" or "IIS Web server" and both of these options have their pros and cons but I'm not going to get into that because that is another blog post if you ask me.  Below is an image of the properties tab Web.

 

Usually when I'm starting out on a new project I've always found myself always using the "Visual Studio Development Server" for debugging but once I start publishing my sites to IIS then I usually switch to "IIS Web Server" but one of the biggest problems that I've had was not being able to switch back to "Visual Studio Development Server" mode and successfully publish my code to the desired IIS website.  Whenever I would switch back and try to publish my code to the IIS website I would get this error.

 

This error has haunted me for about 2 or 3 projects and I finally got tired of it and started to do some searching to find a fix but was unable to.  So I started messing around with the settings on the Web properties tab and noticed that the "Project Url" and "Override application root URL" textboxes were getting pre-populated and in most cases I was changing the values to point to the IIS website I published to.

 

Once I noticed that these values were not being cleared out when I would click on the "Use Visual Studio Development Server" radio button then I decided to clear them out manually and then try publishing again.  When I tried the publishing everything worked and the error went away.  So when you switch back and wan't to use the publish feature but you can't because of the error message, just make sure everything is cleared out and looks like this image below.

 

I'm sure everyone in the world knows this but since this was my first I figured I would blog it.  Hope everybody had a great weekend.

Cheers

Tags:

Microsoft Visual Studio 2005

Using The expression option and XPath statement for comparing two values in InfoPath 2007 Condition statement

by michaellotter 18. January 2008 09:59

In the post Using InfoPath 2007 Translate function to do what XPath lower-case function does I talked about how to use the “translate” function in a XPath expression box and today I just wanted to continue down the path of using XPath expression box and XPath to compare two values in a Condition statement. In a normal circumstance this would be a very easy thing to do because you would just go select the two fields you want to compare and boom you’re done but what if the two field values are not always the same case. Then what do you do? How do you make everything the same case for both fields? This is a situation that I ran into not long ago and below is how I went about solving the problem.

Whenever building a condition statement you only have the options of choosing an existing Field, Group or “The expression” for the first dropdown list and in normal circumstances this would be fine. In normal circumstances if I wanted to compare two values and they were not fields already in the data source and they would not be visible fields then I would create a new Group called “HiddenFields” and then add the fields to that group and populate them in an opening rule. An example of the condition statement that I’m talking about is below.

 

This works great if all you want to do is a simple comparison and the field values will always be the same text case. As I stated above what if you run across a situation when the text case is going to be different in each field but you still want to compare. You might be thinking that you can use the "Use a Formula" option for each field but unfortunately the "Use a Formula" option is only available for the third dropdown. Below you can see what options are available for each dropdown.

 

 

After looking at the pictures you might have noticed you don't have all the selections available in the first dropdown list that you have in the third one. You're probably thinking that this is going to be very difficult to accomplish but in all actuality it's pretty simple if you use the "The expression" option.

When using the "The expression" option there are a couple of things that you can do to make your life a lot easier when building the XPath statement. If you first build the formula for the third dropdown list before changing the first dropdown list to "The expression" then it will copy everything you did into the XPath statement. I usually set the second and third dropdown list values before switching to "The expression" option in the first dropdown list. If you do it this way then you should get something like the below image when you switch.

 

The formula should look like this.

. = translate(my:HiddenFields/my:Field2, "ABCDEFGHIJKLMNOPQRSTUVWYXZ", "abcdefghijklmnopqrstuvwyxz")

The formula is now 2/3 the way done and now all we have to do is build and add the formula for the first field. The easiest way to do it for this example since the fields are in the same "Group" is to copy the current formula and replace the "." with it and then change the "my:Field2" text to "my:Field1". You might be saying that field box is too small and you wish you had more room to view the formula. If that's the case then open "Notepad" and do all you're editing in there and then paste it back into the field when you're done. At the end the condition box should look like the image below.

 

The formula should look like this.

translate(my:HiddenFields/my:Field1, "ABCDEFGHIJKLMNOPQRSTUVWYXZ", "abcdefghijklmnopqrstuvwyxz") = translate(my:HiddenFields/my:Field2, "ABCDEFGHIJKLMNOPQRSTUVWYXZ", "abcdefghijklmnopqrstuvwyxz")

Having the flexibility to add a formula to your fields when you compare them should open your world to a lot of new options.  Well it's time for me to get back to work and start preparing for my next gig that starts next week.  I'm pretty excited about this one because it sounds like I'll be doing a lot of cool SharePoint development work.

Cheers

Tags:

InfoPath 2007 | InfoPath Xpath Functions

Code Camp and User Group presentations and code projects

by michaellotter 14. January 2008 22:10

Over the last few months I've spoke at 4 different events and have really enjoyed myself but I hadn't got around posting my presentations and code projects because other things kept me busy and I kept forgetting to.  This week I'm at home finishing up some code projects and have found some extra time to spend on my blog and catching up on other things.

Today I got around adding a new page to my blog for the presentations and code projects and just a few minutes ago uploaded all my presentations.  You can find them at http://www.sharepointblogs.com/mdlotter/pages/code-camp-and-user-group-presentations.aspx and later this week I'll add my code projects to.  I've really enjoyed speaking at these events and meeting a lot of new people.  I'm hoping that I'll have a lot more entries on this page this year and mean years to come.

Cheers

Tags:

Public Speaking | Code Camp | User Group Meeting

Visual Studio 2008 VSTO and InfoPath-2007 error when trying to run debug

by michaellotter 13. January 2008 22:24

On Saturday when I was adding my finishing touches to my demo for the Philly Code Camp I ran into an error with Visual Studio 2008 VSTO and InfoPath 2007. Whenever I tried to run my InfoPath 2007 form in debug mode I got the following error.

 

"Microsoft Office InfoPath does not recognize some or all of the command line options. Exit and restart Microsoft Office InfoPath with the correct command line options"

When I discovered this error and found out that it happened with a brand new project my heart started to beat a little faster (ok lot faster) because I knew the pressure was on to fix the problem before my session started. I started to do searches on the internet and I couldn't find any answers and then I did one final search and I found some link that talked about a similar error with Visual Studio 2008 Beta 2 and another office application. It mentioned about updating Office 2007 with a patch to fix the error. After reading that I looked at the version I was running and notice that I wasn't running SP1 for Office 2007 and decided to install that and see if it would fix the error. Luckily I had internet access at the code camp and started the download and about 30 minutes later I got it downloaded and installed. Then I crossed all my fingers and toes and tried the debug mode again and it worked. By installing SP1 for Office 2007 fixed the problem. I'm sure there will be many more little things pop-up and if I run into them I'll be sure to post them.

By the way Philly code camp rocked the house and I'm glad that I got a chance to speak.

Cheers

Tags:

InfoPath 2007 | Microsoft Visual Studio 2008

Speaking at Philly Code Camp on January 12th

by michaellotter 5. January 2008 13:06

The Philly.Net Code Camp is coming up on Saturday, January 12th at DeVry University in Fort Washington, PA and I'm happy to say that I will be giving a presentation at the event.  The presentation is titled "InfoPath 2007 with Visual Studio 2008".  The session walks through building a new InfoPath 2007 form, Web Service, .NET Class, Workflow and LDAP query with Visual Studio 2008.  The form will call the web service on opening to retrieve the current user Active Directory information and State list from SQL 2005 database to populate an InfoPath form drop down list.   A simple workflow will be created and deployed with Visual Studio 2008 for sending an email.  This presentation will cover more details than what I usually do and it will all be using Visual Studio 2008 and not 2005.  Information on attending and a list of all the tracks for the code camp can be found at http://www.philly.net.

In my opinion the Office track is jammed pack with great sessions and we have Bob Fox doing a session on SharePoint Disaster Recovery and Backup (Wow can't what to see what type of code Bob has).  A full list of all the Office sessions is listed below.

David Mann - Delivering Modular SharePoint Workflow Functionality via Components
Bob Fox - SharePoint Disaster Recovery, Backup and more...
Tony Testa - AJAX in SharePoint
Michael Lotter - InfoPath 2007 with Visual Studio 2008
Russ Basuira - Programming Composite Applications that use the SharePoint Business Data Catalog
Gary Blatt - Using OpenXML to Access Excel and other Office 2007 Files

I'm really excited about this opportunity because it gives me another opportunity to meet new people and to work on my speaking and presentation skills.  The last 2 code camps were a blast and I'm sure this one will be to, please come out and join us for a great time talking about writing code (things we love to do) and meeting new people.

Cheers

Tags:

Public Speaking | Code Camp

About me

Michael Lotter
B&R Business Solutions
SharePoint Solution Architect
MCTS
More...

 

SharePoint Saturday

SharePoint Saturday is a free event open to the public and is focused on all aspects of SharePoint and related Microsoft Office technologies.  
  

 

 

 

 

 

 

Calendar

<<  March 2010  >>
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

RecentComments

Comment RSS