Short solution for short problems

Retrieving DataItems on IndexChanged event

Recently I was looking for a way to retrieve a particular column based on it's column name (instead of fixed cellnumber) when a row in a GridView has been selected. I came up with the following which does the trick:

protected void gvGeneratedReports_SelectedIndexChanged(object sender, EventArgs e)
    GridView gv = (GridView)sender;
    DataRowView rowView = (DataRowView)gv.SelectedRow.DataItem;
    string outputType = rowView["OutputType"].ToString();

Copying rows from DataTable A to DataTable B

It's amazing how often we need to copy data from one DataTable to another. This is how you can the job done:

// PRESUPPOSITION: Already instantiated dataTableA
DataTable dataTableB = dataTableA.Clone();
dataTableB.TableName = "CloneOfA";
// Copy records from dataTableA to dataTableB
foreach (DataRow dr in dataTableA.Rows){    dataTableB.ImportRow(dr);}

MOSS: Group list by month using calculated fields

How to group a list or library by month if you have a field containing Dates?


Simple, create a calculated field in your list or library that returns a string.

Use this code: =TEXT(Date,"yyyy - ")&TEXT(Date,"mm")&TEXT(Date," (mmmm")&TEXT(Date," yyyy)")

Now group by this field and that's it!

You can find everything on functions that you can use in calculated fields on: http://office.microsoft.com/en-us/sharepointtechnology/HA011609471033.aspx

Country or postal code list box

In some enterprise applications you need to show geographical data such as countries and postcodes. Most of the time you need it for a registration page, where the user need to fill in the country and postcode/area.

Geonames is a free geographical database that contains over 8 million geographical names and it can be accessed through a number of webservices. For example the url http://ws.geonames.org/countryInfo? gives an xml with all countries, whereas the following request http://ws.geonames.org/postalCodeSearch?placename=be gives us all postcodes for a particular country (e.g. Belgium).

Most likely you need two dropdown lists, one for countries and one for postcodes, where the postcode dropdown is dependent from the country dropdown list. This is a very good example to introduce AJAX by using the CascadingDropdown that is included in ASP.NET AJAX.

To implement this functionality we need to implement two methods on a webservice, namely GetCountries and GetPostalCodesByCountry.

Source url = http://www.delarou.net/weblog/PermaLink,guid,34dab161-3d1d-4e1a-b786-d79a9cc04447.aspx

Auditing in MOSS 2007

MOSS 2007 auditing. In many cases it is useful to know how many times a document is opened.Sometimes even when and who? Moss 2007 offers auditing as a standard solution for this need. This is what Microsoft has to say about Auditing: Office SharePoint Server 2007 goes even further and enables auditing at the list or document library level, and control over what types of events should be recorded in the audit log. Office SharePoint Server 2007 also provides a reporting function that uses Microsoft Office Excel workbooks to display and keep records of audit logs. Therefore, Office SharePoint Server 2007 enables you to take advantage of the Windows SharePoint Services auditing support without having to write any custom code. In MOSS 2007 it is possible to track several events on list items.This is done with information management policies. Here’s a good definition about the extra’s Sharepoint server 2007 provides: Office SharePoint Server 2007 provides an administrative user interface that allows you to enable and configure auditing without having to write any code. And office SharePoint Server 2007 provides a reporting aspect. More specifically, Office SharePoint Server 2007 makes it possible to generate Excel workbooks that contain the information about audit events within the Windows SharePoint Services audit log.  So MOSS makes it easy for us to track and report usage of documents and lists. Here how Microsoft describes the configuration of auditing: 

We start by examining the built-in Office SharePoint Server 2007 support for configuring auditing within a site collection. Go to the site setting page of any site within a server farm that has Office SharePoint Server 2007 installed. You find that many links are added here by Office SharePoint Server 2007-specific features. Inside the Site Collection Administration section, locate a link with the caption Site Collection audit settings as shown in Figure 7.


Figure 7. Site Collection Administration



Clicking the Site collection audit settings link opens an Office SharePoint Server 2007-specific application page named AuditSettings.aspx. This page provides a user interface (Figure 8) for enabling and configuring auditing settings for the current site collection. As shown in the Figure 8, the AuditSettings.aspx application page makes it possible to configure site collection auditing at various levels of granularity.


Figure 8. AuditSettings.aspx page



In addition to configuring auditing at the site collection level, Office SharePoint Server 2007 also enables you to configure auditing at a much more detailed level. This support is made possible through the information management policies feature that is included in Office SharePoint Server 2007.

An information management policy consists of a set of rules that a site administrator can define and then apply to a certain type of content. The rules for an information management policy are created and configured in terms of policy features. Features that are provided by default with Office SharePoint Server 2007 include support for auditing, expiration, document labels, and bar codes. The programming model for policy features is also extensible, which allows developers to create their own custom policy features. For developer resources, see the appendix at the end of this article.

Office SharePoint Server 2007 enables you to create and configure an information management policy for a specific instance of a list or document library. You can also create an information management policy for a content type, which then applies to list items and documents in any list or document library that is defined in terms of that content type. The ability to apply information management policies to content types is valuable because it provides more granular control than site collection level auditing. It also mitigates the need to configure audit settings at the level of list instances or document library instances.

Office SharePoint Server 2007 also enables you to define information management policies at the site collection level. This provides extra manageability, because you can define an information management policy once within a site collection, and then apply it to your choice of lists, document libraries, and content types within that site collection.

The Site Settings page has a link with the caption Site collection policies. If you click this link, it opens an application page named Policylist.aspx. This allows you to configure a custom policy, which is scoped to the current site collection. Figure 9 shows an example of a custom policy that was created to configure a standard set of audit events that can be applied to any list, document library, or content type.


Figure 9. Custom policy page



After you define a custom policy at the site collection level, you can then go to the List Settings page for a list or document library. You find a link with the caption of Information management policy settings, as shown in Figure 10. If you click this link, it redirects you to an application page named Policy.aspx, which enables you to create a new information policy. Alternatively, you can apply a policy that is already defined at the level of the site collection. On a server farm with Office SharePoint Server 2007 installed, the Windows SharePoint Services page that enables you to create and configure content types also provides a link that takes you to Policy.aspx. Here you can also create or apply policies.


Figure 10. List Settings page



Figure 11 shows the options that are available through the application page policy.aspx. This is a simple way to apply a custom policy created at the site collection level. It also enables you to define and configure a unique policy that applies only to the current list, document library, or content type. In many cases it promotes a higher level of manageability. For example, you can create all of your policies at the site collection level, and then simply apply your policies to the appropriate lists, document libraries, and content types.


Figure 11. Applying custom policies



This  can also be found at:http://msdn2.microsoft.com/ look for: OfficeSharePointServer2007 ValueAddedSupportforAuditing  When you start using this nice feature, you may find strange results when generating a report. This is because most events only work with office documents. If you try to check how many times a specific pdf document in a library has been viewed, it's impossible. So if you need to now how many times a certain non-Office document has been viewed, then you find yourself writing custom code. Maybe I'll try to figure this out later on.

Google maps

If you want to visualize coordinates, addresses, etc... it is easy to use Google maps.

There are 2 ways to implement Google Maps.

1 Use the Google API in your site.

You need to do 2 things to implement this in your site.

Use this code on the page you want to show the google map:

This key is good for all URLs in this directory:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml">
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps JavaScript API Example</title>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAoVpHiXx5oCNbL2RPHM9crRSqaiXgH3

    <script type="text/javascript">
    function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 13);
  <body onload="load()" onunload="GUnload()">
    <div id="map" style="width: 500px; height: 300px"></div>

Check out the API documentation for more information.

* Request a key at: http://www.google.com/apis/maps/signup.html. For testing you can fill in the localhost and use that key, don't forget to change this once in production.


2 Show the map in a pop-up or Iframe using url reference.

You can link the page to this url: http://maps.google.com/maps?spn=0.030372,0.068665&z=6&t=h&vp=53.859462,-3.038235 and use following query string parameters after the link:

q= Query - anything passed in the q parameter is treated as if it had been typed into the query box on the maps.google.com page. In particular:
a precise address is looked up and a marker and info box is displayed at the specified point
a town name, or the first half of a postcode causes the region to be displayed with to marker or info box
an exact location can be specified as latitude,longitude, in decimal form (52.123N,2.456W or 52.123,-2.456) or as degrees, minutes and seconds (52 7 22.8N,2 27 21.6W or 52 7 22.8,-2 27 21.6) or as degrees and minutes (52 7.38N,2 27.36W or 52 7.38,-2 27.36).
any text added in parentheses () is displayed in the info window and sidebar in bold, there appears to be no way to cause a line break, but you can use %A0 as a "no break space" to prevent line breaks happening where you don't want them.
the words "to" and "from" cause the driving directions function to be activated.
the word "near" or "loc:" causes the local search function to be activated
space-ampersand-space (use +%26+ or %20%26%20 in URLs, not +&+ or +&amp;+ otherwise the ampersand gets treated as a separator) can be used between the names of two streets to specify an intersection.
A location can also be specified after an at sign, in decimal form (@52.123,-2.456). This gives a lower zoom level than using the same values without the at sign. Using this format interferes with other options of the query parameter. The @ sign instead of "near" or "loc:" tends to cause only a single business result to be displayed, compare (Church near Hallows Road Blackpool, Lancashire) which returns over 1000 results to (Church @ Hallows Road Blackpool, Lancashire) which returns one result.
The full URL of a Google Earth .KML/.KMZ file or a RSS feed that includes GeoRSS data, can be used, and the contained information will be displayed on the map.
ll= Latitude,longitude of map centre - Note the order. Only decimal format is accepted.
If this is used without a query, then the map is centred at the point but no marker or info window is displayed
sll= Latitude,longitude of the point from which the business search should be performed. You could use this to perform an off-centre busness search. Google use it so "link to this page" can record a map that has had the centre moved after performing a business search.
spn= Approximate lat/long span. The zoom level will be adjusted to fit if there's no &z parameter.
sspn= ?? lat/long of... what?
hl= Host language - only a few languages are supported, e.g. &hl=fr for French.
t= Map Type. The available options are "m" map, "k" satellite, "h" hybrid
saddr= Source address. Use this when asking for driving directions
any text added in brackets is displayed in the sidebar in bold
daddr= Destination address(es). Use this when asking for driving directions
any text added in brackets is displayed in the sidebar in bold
"+to:" clauses can be appended to the destination to request multiple destination routing, like this "&dadr=Blackpool+to:Manchester+to:Leeds"
text in brackets can also be added to the "+to:" clauses.
mrad= Additional destination address.
If you've got three points in your trip you can use &saddr, &daddr and &mrad instead of "+to:" clauses.
start= Skips the first (start-1) matches
num= Display, at most, this number of matches. The valid range is 0 to 10 (but 0 is a bit pointless).
near= Can be used as the location part of a query instead of putting the whole thing into &q.
f= Controls the style of query form to be displayed. &f=d displays the "directions" form (two input boxes: from, to), &f=l displays the "local" form (two input boxes: what, where). Otherwise the default search form is displayed (single input).
output=html Uses the old style Google Local page format from before it merged with Google Maps, with the small map and large sidebar.
output=js Outputs JavaScript object literals and function calls used by Google Maps, including encoded polyline data for driving directions, and stage information in HTML format.
output=kml Outputs a KML file containing full Placemark information representing the current map.
output=nl Outputs a small KML file containing a NetworkLink wrapper linking to a URL from which Google Earth and Google Maps can obtain the Placemark information.
latlng= This is a weird one. It takes three numbers separated by commas. The first two numbers (presumably representing latitude and longitude multiplied by 1000000) are ignored. The third number seems to be a Google internal "Company ID" number for a particular business. E.g. &latlng=0,0,14944637421527611642 represents Blackpool Community Church. Specifying this parameter performs a Google Search for pages that reference that business, and displays a tiny map. Other parameters, in particular &q, must have valid contents (but need not relate to the target business) for this to work.
cid= Similar to latlng, but generating a different map size. It takes three numbers separated by commas. The first two numbers (presumably representing latitude and longitude multiplied by 1000000) are ignored. The third number seems to be a Google internal "Company ID" number for a particular business. E.g. &cid=0,0,14944637421527611642 represents Blackpool Community Church. Specifying this parameter displays a large map of the identified company location. Other parameters, in particular &q, must have valid contents (but need not relate to the target business) for this to work.
vp= The presence of this parameter causes maps.google.com to switch into Copyright Service mode. Instead of returning the html that draws a map, it returns information about the copyright ownership in Javascript format. The &vp parameter specifies the viewpoint (i.e. the centre of the map). Copyright Service only works when the &spn and &z parameters are also supplied, indicating the span and the zoom. Optional parameters are &t, which specifies the map type, and &key which specifies the API key of the site performing the request. E.g. http://maps.google.com/maps?spn=0.030372,0.068665&z=6&t=h&vp=53.859462,-3.038235
om= The presence of this parameter with a value other than 1 causes the overview map to be closed. If the parameter is omitted, or present with the value 1, then the overview map is open.
ie= Can be used to specify the character set. e.g. &ie=UTF8.
pw= Activates print mode and initiates printing. There seems to be a problem at the moment with &pw=1, but using settings like &pw=2 is OK.
z= Sets the zoom level.
iwloc= Specifies where the infowindow will be displayed. In a business search &iwloc=A to &iwloc=J will open the info window over the corresponding business marker, and &iwloc=near will place it over the big green arrow if that's currently displayed. &iwloc=addr can be used on map search to explicitly request the info window to be open on the address, but that's the default anyway. Directions search supports &iwloc=start, &iwloc=end and &iwloc=pause1 etc.
layer=t Activates the traffic overlay
msa=b Activates the "My Maps" sidebar when used in conjunction with "maps.google.com/ms". It does nothing without the "/ms" and "/ms" does nothing without the "&msa=b".
msa=0 Involved in My Maps processing. Possibly specifies the My Maps server number.
msid= Specifies a My Maps identifier. When used in conjunction with "maps.google.com/ms" and &msa=0, the corresponding My Map is displayed.
mrt=kmlkmz Skips the normal search and goes directly to User-Created Content. Only works if the query contains a location and something to search for. E.g. q=hotel&near=london&mrt=kmlkmz or q=hotel+in+london&mrt=kmlkmz.
view= Can be used to select text view (view=text) or the normal map view (view=map)
dirflg=h Switches on "Avoid Highways" route finding mode.
Retrieved from "http://mapki.com/wiki/Google_Map_Parameters"

AD properties

results.ToArray(){Dimensions:[84]}    [0]: "lastlogoff value 0"    [1]: "instancetype value 4"    [2]: "streetaddress value MyStreet 14"    [3]: "l value Location"    [4]: "samaccounttype value 80530456"    [5]: "lockouttime value 0"    [6]: "c value BE"    [7]: "codepage value 0"    [8]: "mobile value +32 (477) 820 088"    [9]: "pwdlastset value 128493474314166972"    [10]: "mdbusedefaults value False"    [11]: "scriptpath value INT-ORG\\Location\\Logon\\logon.bat"    [12]: "homemta value CN=Microsoft MTA,CN=orgDEKOLEXC01,CN=Servers,CN=Germany Administrative Group,CN=Administrative Groups,CN=orgNTLMAIL,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=orgNTL,DC=NET"    [13]: "logonhours value System.Byte[]"    [14]: "objectcategory value CN=Person,CN=Schema,CN=Configuration,DC=orgNTL,DC=NET"    [15]: "garbagecollperiod value 0"    [16]: "msrtcsip-userenabled value True"    [17]: "co value Belgium"    [18]: "accountexpires value 2650466844000000000"    [19]: "msexchhomeservername value /o=orgNTLMAIL/ou=Germany Administrative Group/cn=Configuration/cn=Servers/cn=orgDEKOLEXC01"    [20]: "usnchanged value 42811172"    [21]: "displayname value Lastname, firstname"    [22]: "whencreated value 19/01/2006 1:29:26"    [23]: "postalcode value 3001"    [24]: "msexchalobjectversion value 332"    [25]: "description value Standard Account - IMDL: 1000019358"    [26]: "company value 1062 Comp name."    [27]: "countrycode value 0"    [28]: "userprincipalname value user@orgNTL.NET"    [29]: "homemdb value CN=Journal Store 1-1 (orgDEKOLEXC01),CN=Storage Group 1 (orgDEKOLEXC01),CN=InformationStore,CN=orgPCNAME,CN=Servers,CN=Germany Administrative Group,CN=Administrative Groups,CN=orgMAIL,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=org,DC=NET"    [30]: "name value Lastname, firstname"    [31]: "objectsid value System.Byte[]"    [32]: "usncreated value 389796"    [33]: "orgimdlattribute1 value 1000019358"    [34]: "legacyexchangedn value /o=orgNTLMAIL/ou=Germany Administrative Group/cn=Recipients/cn=user"    [35]: "logoncount value 3358"    [36]: "samaccountname value user"    [37]: "mdboverquotalimit value 500000"    [38]: "givenname value firstname"    [39]: "whenchanged value 2/04/2008 8:36:31"    [40]: "profilepath value \\\\orgbeleufnp01\\UserProfiles\\XP\\user"    [41]: "msrtcsip-primaryuseraddress value sip:firstname.Lastname@orgntl.com"    [42]: "title value IS systems analyst"    [43]: "useraccountcontrol value 544"    [44]: "msexchmailboxsecuritydescriptor value System.Byte[]"    [45]: "mdbstoragequota value 450000"    [46]: "facsimiletelephonenumber value +32 (16) 387 001"    [47]: "msexchomaadminwirelessenable value 0"    [48]: "textencodedoraddress value c=CH;a=org;p=orgNTLMAIL;o=org Switzerland RGC;s=Lastname;g=firstname;"    [49]: "proxyaddresses value sip:firstname.Lastname@orgntl.com"    [50]: "msexchhidefromaddresslists value False"    [51]: "mailnickname value user"    [52]: "url value http://www.orgntl.de/"    [53]: "lastlogon value 128522771256226187"    [54]: "msexchmailboxguid value System.Byte[]"    [55]: "publicdelegatesbl value CN=SUBORGB\\, Helpdesk,OU=Generic Accounts,OU=Users,OU=Location,OU=INT-SUBORG,OU=org,OU=Users & Workstations,DC=orgNTL,DC=NET"    [56]: "department value PM Research Laboratories GmbH"    [57]: "adspath value LDAP://CN=Lastname\\, firstname,OU=Employees,OU=Users,OU=Location,OU=INT-SUBORG,OU=org,OU=Users & Workstations,DC=orgNTL,DC=NET"    [58]: "badpwdcount value 0"    [59]: "objectclass value top"    [60]: "extensionattribute15 value GUM"    [61]: "extensionattribute5 value S-1-5-21-1009579374-2342361561-4147951735-148116"    [62]: "deleteditemflags value 0"    [63]: "objectguid value System.Byte[]"    [64]: "distinguishedname value CN=Lastname\\, firstname,OU=Employees,OU=Users,OU=Location,OU=INT-SUBORG,OU=org,OU=Users & Workstations,DC=orgNTL,DC=NET"    [65]: "telephonenumber value +32 (16) 387 000"    [66]: "badpasswordtime value 128516877748746025"    [67]: "manager value CN=Schoonjans\\, Kristof,OU=Employees,OU=Users,OU=Location,OU=INT-SUBORG,OU=org,OU=Users & Workstations,DC=orgNTL,DC=NET"    [68]: "memberof value CN=org DE KOL UR Lims_Dev Users,OU=Security,OU=Groups,OU=Cologne,OU=INT-SUBORG,OU=org,OU=Users & Workstations,DC=orgNTL,DC=NET"    [69]: "msexchuseraccountcontrol value 0"    [70]: "mail value firstname.Lastname@orgntl.com"    [71]: "showinaddressbook value CN=All Users,CN=All Address Lists,CN=Address Lists Container,CN=orgNTLMAIL,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=orgNTL,DC=NET"    [72]: "msrtcsip-primaryhomeserver value CN=LC Services,CN=Microsoft,CN=orgRTC,CN=Pools,CN=RTC Service,CN=Microsoft,CN=System,DC=orgNTL,DC=NET"    [73]: "msexchpoliciesincluded value {C165CBA7-E974-4B20-8DA4-9A15688E13EC},{26491CFC-9E50-4857-861B-0CB8DF22B5D7}"    [74]: "lastlogontimestamp value 128515987265472270"    [75]: "employeetype value org Employee"    [76]: "sn value Lastname"    [77]: "extensionattribute9 value 50402995"    [78]: "extensionattribute4 value firstname.Lastname@orgntl.com"    [79]: "primarygroupid value 513"    [80]: "userparameters value CtxCfgPresent"    [82]: "dscorepropagationdata value 19/01/2008 9:22:16"