Tuesday, December 13, 2016

PetaPoco nuances and triggers

The PetaPoco shortcut ppDB.Insert(obj) or ppDB.Update(obj) cannot be used if the database table has trigger because the following error will be generated:

“The target table '[db table name]' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause.
  

This is because the sql generated by PetaPoco is the following:
INSERT INTO [db table] ([col1], [col2], ... [coln]) OUTPUT INSERTED.[identityColName] VALUES (@0,@1,...@n)

PetaPoco nuances with transactions

PetaPoco has a couple of really easy ways of inserting/updating records. 

The following are the object initializations used below:

private PetaPoco.Database ppObj = new PetaPoco.Database("[connection string name]");
ClassName.ObjName objInstance = new ClassName.ObjName();


One way is to create an object based upon the class created from the database.tt file and use the insert()/update() method:
objInstance.Insert();

As I found out, this approach does not allow you to rollback a transaction. If you run the insert()/update() on the PetaPoco object instead then you can rollback transactions:
ppObj.Insert(objInstance);

Monday, December 12, 2016

Trapping emails generated in C# when there is no SMTP server

If you need to generate emails in your app, I’ve found a way to test them in the dev environment. Visit http://smtp4dev.codeplex.com/downloads/get/269147 and download the tool. The executable in the ZIP file will spawn a mini-smtp server. Click the “options” button and then the “server” tab. Set the listen interface to 127.0.0.1, I think you can leave the port at 25.
Add the following to your web.config file in the <configuration> section. Port will be whatever number you specified for smtp4dev:
<system.net>
   <mailSettings>
     <smtp>
       <network host="localhost" port="25" />
     </smtp>
   </mailSettings>
</system.net>
Write your code as normal to generate & send the email. Smpt4dev will notify you that you’ve received an email and you can click the “view” button to see the email message in Outlook.
The app sits in the tool tray under “hidden icons”, so no need to start the executable again. Closing the smpt4dev UI doesn’t end the process and running the exe again will produce a “server failed” message as shown below. View hidden icons in the tool tray close any extra occurrences of smtp4dev.

Monday, August 16, 2010

Linq-to-SQL and Identity Columns

I recently had a situation where I had to insert records into a db table. The table had an identity column but no primary key (go figure). This presented hurdle 1 of how to insert the records since linq-to-sql's standard approach of creating a new table item, populating the fields and then inserting the new record only works if your table has a primary key.

Hurdle 1 was overcome by creating a dynamic SQL statement and using ExecuteQuery. This was fine until I had to retrieve the ID of the record that was just inserted (Hurdle #2). appending select scope_identity() after my insert statement was not playing nicely. If I specified the ExecuteQuery to be of type I would receive "Specified cast not valid". If I specified the ExecuteQuery to be of type the identity column was 0.

I overcame hurdle #2 with the following:
1) specified the ExecuteQuery to be of type
2) generated the following SQL Statement: "; select * from where = (select scope_identity())"

This returned a full record from the table with the correct value in the identityColumn property

Friday, February 19, 2010

Nintex SharePointTaskId, InfoPath, and conditional formatting

I was recently working on an InfoPath form that was used to drive a Nintex workflow. I had gotten to the point where I needed to make sure not just any ole user could respond to a task as terrible things happened (the rules in the InfoPath form were applied, but the workflow would not move forward and chaos ensued).

My search began with the SharePointTaskId property in the GetRunningWorkflowTasksForCurrentUser web service method that Nintex provides. I noticed some oddities in the process:

1) in code, the value was always empty. just to make sure I wasn't hallucinating I copied the outerxml of my xpath query. every node in the subtree had an empty value. YET, if I applied conditional formatting by saying "is not blank", it worked.

2) if I tried to perform conditional formatting by saying where SharePointTaskId is blank, it did not work. This had me scratching my head since the "is not blank" worked perfectly.

My solution for the second issue was to compare the WorkflowName property against a pattern (e.g. WorkflowName does not match pattern \p{L}+ -- in other words, WorkflowName has to have at least 1 letter)

Tuesday, January 19, 2010

Moving Nintex Workflow to a new site

As stated in an earlier blog my team was tasked with creating a SharePoint staging environment that mirrored production. Part of the SharePoint site included Nintex workflows. This did not go as smoothly as I had thought, either. Even though central admin indicated that the connection to the database had been established, whenever I tried to view my existing workflows in the SharePoint site I would see the following message: Failed to open a connection to the Nintex Workflow configuration database.
System.Data.SqlClient.SqlException: Cannot open database "" requested by the login. The login failed. Login failed for user ''.


I stumbled upon this thread on the Nintex site which pointed me to the resolution. The appPool user account needed: 1) permissions to the Nintex database; 2) to be added to the role WSS_Content_Application_Pools

reason #312 why I hate SharePoint

I know, everyone has many reasons to hate SharePoint, and they are all valid. So, this is really just another in a long stream, but I wanted to share it any way.

We were tasked to create a staging environment which mirrored production. Sounds simple, right? Wrong. The first naive step was to create a site collection backup of production. Getting it onto the staging environment proved painful enough due to its size, but after it was finally uploaded I thought we were home free. The restore failed... repeatedly... miserably. The error message that displayed was: "The site collection could not be restored. If this problem persists, please make sure the content databases are available and have sufficient free space." I tried increasing the database size. I freed up room on the hard disk. I created a blank SharePoint site and tried to restore into that since every time I ran the restore into the existing SharePoint site the database just kept getting bigger, bigger than the production database, even though I was specifying "overwrite".

After happening upon a post where a restore was generating the same error message I noticed one responder said to can the whole site collection restore notion and just do a backup/restore of the content database.

I did it, it worked. W00T! It's not complete in that we still have to manually get the customizations back into the site, but it at least got us about 85% - 90% there.

Another reason VB.Net is inferior to C#

A while back I developed a custom module in DNN for a client. Due to my desire to type as little as possible I used the letters from the client's name to create the namespace -- ASC. We had been running DNN 4.8 and all seemed fine until I was told to upgrade to 5.1 Somewhere along the line the DNN core code had been modified to make a call to a VB.Net method Asc. Since VB.Net is *NOT* case sensitive like C# this caused a host of problems - mainly, the site would not load and there was no kind error message informing me as to what had happened.

After rewriting and redeploying my DLL to use a different namespace all was right with the world, but I wasn't happy.

Tuesday, January 12, 2010

DNN and Fallback Skin Doctype

Recently I was required to upgrade a customer's DNN site from 4.8 to 5.0. Simple enough, right?
1) Copy site folder to another location
2) backup database
3) extract the contents of the upgrade zip file into the site folder
4) navigate to http://SITEURL/install/install.aspx?mode=install
5) VOILA! Upgrade complete

Unfortunately, after doing the upgrade the customer's dropdown menus were no longer appearing on top of the content (we had used CISS.SideMenu for the menuing system) . Upgrading the menu module only made things worse - the menu bar disappeared altogether. So, I reverted back to the 4.8 site and went about replicating their environment on a VM.

Thinking that maybe the problem was DNN 5.0 I decided to go straight to DNN 5.1. The upgrade was successful and in the process I was able to resolve another problem the customer was having - the dropdown menus look garbled in IE 8 unless the site was run in compatability mode. I was stoked and ready to tackle the production server again.

Much to my dismay, after the second upgrade went seamlessly, the same problem appeared. I was ready to throw in the towel. Thanks to a kind co-worker who jogged my memory I was able to resolve the problem.

I had changed the Fallback Skin Doctype on the portal settings screen to XHTML 1.0 transitional on my VM AND on the production server BEFORE doing the upgrade (http://www.dotnetnuke.com/Community/Blogs/tabid/825/EntryId/2130/The-Fallback-Skin-Doctype-and-skinning.aspx). This had been done in an attempt to resolve the IE 8 issue. Unfortunately, the upgrade to 5.1 wiped out this setting. Once I changed it back the menus appeared just fine.

Friday, November 21, 2008

The Dreaded "The SSP Timer Job Distribution List Import Job was not run."

Unfortunately, when I set up some test SharePoint sites on my dev machine I tied service accounts to my network userid & pwd. Our network policy requires that passwords be changed every 90 days, so every 90 days I get into a pickle because I can't remember all that I had to do so that SharePoint would continue to play nice on my machine.

  1. In IIS, change the password of all App Pools that are tied to my network account and restart IIS

  2. At the DOS prompt run stsadm -o updatefarmcredentials -userlogin <domain\userid> -password <new password> followed by iisreset /noforce

  3. In Central Admin:
    • Go to App Management and click on "Manage Search Service" under the "Search" group and change the "Office SharePoint Search Indexing and Query" account's password

    • Click on Shared Services Administration, right-click the default shared service and select Edit Properties and update the password for the SSP Service Credentials

  4. At the DOS prompt run iisreset /noforce

Tuesday, November 18, 2008

How to Show/Hide SharePoint QuickLaunch


The bulk of this comes from http://suguk.org/blogs/sharepointhack/archive/2008/01/29/8093.aspx

Insert the following JavaScript block immediately before the </Head> tag in your master page:


<!--
function showhide(layer_ref)
{
var state = 'block';

var tbl = document.getElementById(layer_ref);
var img = document.getElementById("img" + layer_ref);

if (tbl.style.display == 'block')
{
tbl.style.display = 'none';
img.src = "_layouts/images/BLK_RGT.GIF";
}
else
{
tbl.style.display = 'block';
img.src = "_layouts/images/BLK_LEFT.GIF";
}
}
//-->
</script>

I put the following div immediately inside the TD with ID LeftNavigationAreaCell:
<div id="divOuterQuickLaunch" style="display:block;">

I added the following immediately after the ContentPlaceHolder PlaceHolderTitleAreaSeparator:

<tr>
<td style="text-align:right;">
<a id="lnkregionalNav" style="cursor:hand" onclick="showhide('divOuterQuickLaunch');">
<img src="_layouts/images/BLK_LEFT.GIF" id="imgdivOuterQuickLaunch" alt="Show/Hide Quicklaunch"/>
</a>
</td>
</tr>


If you are looking at a list, the behavior will not be as expected as there is an image at the top of the page that prohibits the quicklaunch area from collapsing when hidden. To correct this, find the ContentPlaceHolder PlaceHolderPageImage and add Visible=”false”

That should do it.

Wednesday, September 17, 2008

Tuesday, September 16, 2008

How To: Create a custom Google map icon

I had found some very valuable resources when I was starting to develop Google maps:

The Google Maps API Reference http://code.google.com/apis/maps/documentation/reference.html

Google Maps API Tutorial http://econym.googlepages.com/index.htm

For specifically creating custom Google maps icons http://googlemapsapi.blogspot.com/2007/04/labeledmarker-v10-do-more-with-your.html

As valuable as those references are I often had a lot of hit and miss trying to get the various pieces to work together. I hope this blog will help someone see how the various pieces get stitched together.

A JavaScript function to create the marker and set up the event window




// point = new GLatLng(lat,lng);
// infoWindowText = text to be displayed in the info "balloon"
// type = which icon to use
// count = which item in the group we are processing (e.g. item 16 out of 120 total)
function createMarker(point,infoWindowText,type,count) {
var xOffset = -1;
var yOffset = -29;

// to get the number to appear within our mappin, the xoffset
// had to be adjusted depending upon what numbered item the
// current location is within our result set
if(count > 99)
xOffset = -7;

else if(count > 9)
xOffset = -4;

bounds.extend(point);
// need to create 1icon for each number will have
// GIcon is explained at http://code.google.com/apis/maps/documentation/reference.html#GIcon
var Icon = new GIcon(baseIcon);
// background is a previously defined array of icon "types", each of which points to its own
// specific .gif
// e.g. background["Gold"] = "../images/mappins/lorange.png";
Icon.image = background[type];
opts = {
"icon": Icon,
"clickable": true,
"labelText": parseInt(count)+1,
"labelClass": "MapIcon",
"labelOffset": new GSize(xOffset, yOffset)
};
// LabeledMarker is explained at http://googlemapsapi.blogspot.com/2007/04/labeledmarker-v10-do-more-with-your.html
var marker = new LabeledMarker(point, opts);

// openInfoWindowHtml is explained at http://code.google.com/apis/maps/documentation/reference.html
// this tells the screen to display an info "balloon" when the user clicks this point on the map
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(infoWindowText);
});
i++;
return marker;

}




in the main Javascript code you will have the following



// create the marker
var marker = createMarker(point,name,html,type,i);
// addOverlay is explained at http://code.google.com/apis/maps/documentation/reference.html
// adds the newly created marker as an overlay on the map
map.addOverlay(marker);


Thursday, September 11, 2008

How To: Associate a custom action with a specific SharePoint list

There are many web sites that discuss how to associate a custom action with a specific SharePoint list. The ones that helped me the most are:
For whatever reason, I was still having problems getting it all to gel together when trying to apply custom actions to the EditControlBlock for a new list feature that I had created. To help me remember for the future, I thought I would recreate the steps here.
When creating my list template, I used the Sharepoint Solution Generator (available for download here: http://www.microsoft.com/downloads/details.aspx?familyid=7BF65B28-06E2-4E87-9BAD-086E32185E68&displaylang=en)
In the ListDefinition.xml and schema.xml files I set the Type attribute to a large number as explained in the sharepointinsight.com link above. In my case, I set the value to 22222. I then deployed my custom list to my SharePoint site.

To create the custom menu items specific to my newly created feature:

1. I started by creating a new folder in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES.

2. I then copied the Feature.xml and ListTemplates\CustomList.xml from C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\CustomList into my new folder.

· In my case, I did not put the CustomList.xml file in a sub-directory but left it at the same level as the Feature.xml file.

· You should rename the CustomList.xml file to a name corresponding with the new list that was created (ex. NewListNameListFeatures.xml)

3. I modified the Feature Title, Feature Description and ElementManifest Location attributes in my Feature.xml to be specific for my list feature

· The ElementManifest Location attribute must match the filename specified in step 2

4. In the CustomList.xml file, renamed of course, I entered the following (click the image for a larger view):

For this specific scenario to work, some items of note are:

· The RegistrationId attribute must match the “Type” value used when creating the custom list.

· The Location attribute must be “EditControlBlock” for the new menu item to appear in the per-item edit control block menu

· There is no GroupId attribute if Location is EditControlBlock

· The RegistrationType attribute must be “List”

· I didn’t see anything specific about what the Id attribute should be, I simply used a naming convention of ListName-and-Action.

· The UrlAction Url attribute can be JavaScript instead of an actual url (e.g. Url="javascript:window.open('http://www.google.com');".

5. I then installed and activated my custom action using stsadm:

· stsadm -o installfeature -name <folder where custom action resides>

· stsadm -o activatefeature -name <folder where custom action resides> -url <my SP site url>

· iisreset


Voila! My list now has a new item in the edit control block menu.