Function EndPause { Write-Host "Press any key to continue ..." $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") } $x = [System.Reflection.Assembly]::LoadWithPartialName(”Microsoft.SharePoint”) $siteUrlDev = "http://devsite/testsite/" $siteUrlStg = "http://stgsite/testsite/" $siteUrlProd = "http://prodsite/testsite/" Try { $spSite = new-object Microsoft.SharePoint.SPSite($siteUrlStg) } Catch {} Try { $spSite = new-object Microsoft.SharePoint.SPSite($siteUrlDev) } Catch {} Try { $spSite = new-object Microsoft.SharePoint.SPSite($siteUrlProd) } Catch {} if ($spSite -eq $null) { "ERROR ------------ Site not found. Quitting." EndPause exit } $spWeb = $spSite.OpenWeb() $spList = $spWeb.Lists["ListName"] if ($spList -eq $null) { "ERROR -------- ListName list not found. Quitting" EndPause exit } else { {ListName list found} } If (!$spList.Fields.ContainsField("newdatefield")) { # $spList.Fields.Add("test","DateTime",0) $dateField = $spList.Fields.CreateNewField("DateTime","newdatefield") $dateField.DisplayFormat = [Microsoft.SharePoint.SPDateTimeFieldFormatType]::DateOnly $dateField.Required = $false; $spList.Fields.Add($dateField) "Added newdatefield field" } else { "newdatefield field already added. This is fine." } if (Test-Path ("MySPApp.wsp")) { Set-Alias -Name stsadm -Value $env:CommonProgramFiles"\Microsoft Shared\Web Server Extensions\12\BIN\STSADM.EXE" Write-Host "Upgrading solution to 9.0.1" -foregroundcolor green &stsadm -o upgradesolution -name "MySPApp.wsp" -filename "MySPApp.wsp" -immediate -allowGacDeployment -allowCasPolicies &stsadm -o execadmsvcjobs } else { "MySPApp.wsp file missing. Quitting" EndPause exit } EndPause
Monday, October 22, 2012
Sample PowerShell .wsp Install Script
Friday, September 28, 2012
Printing Paginated HTML Page
Update: To just prevent new page on TR breaks add the following style (Note the DOCTYPE!):
<!DOCTYPE html>
<!-- saved from url=(0016)http://localhost -->
<html><head>
<style type="text/css">
@media print
{
tr {page-break-inside:avoid}
}
</style>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <style type="text/css"> /*@media screen print 'print' not working for print preview { }*/ table.splitForPrint { width:681 ; /*assuming 816px for Letter size minus 1.5in margin or approx 135px*/ border: solid 1px #000000;border-bottom: 0; /*turn off bottom since last row will have bottom border*/border-collapse: collapse; font-family: sans-serif;font-style: normal; font-weight: normal;font-size: 12px; } table.splitForPrint td {width:227/*Must divide total width by columns*/; border-bottom: solid 1px #000000;padding:4px;} table.splitForPrint th {border-bottom: solid 1px #000000; background-color: "AliceBlue";padding:4px;} </style> <script src="jquery-1.7.1.min.js"></script> <script type="text/javascript"> //adapted from http://code.google.com/p/wkhtmltopdf/issues/detail?id=168 $(document).ready(function () { $('table.splitForPrint').each(function(i, tabela){ // this to set 'this' context to table var trlength = $('tbody tr', tabela).length; //850:assuming 8.85 in. reserved for tbl height based on 96DPI(http://auctionrepair.com/pixels.html) var maxtrpxperpage = 950; var trsleft = trlength; var pageno = 1; var ultimo = $(tabela); //$('table.splitForPrint').first(); while (trsleft > 0) { var copy = ultimo.clone(); var debugmessage = "<br>starting while loop<br>"; var numtrsremovedfromcurrent = 0; var curtrscount = $('tbody tr', copy).length; var curtbltrscount = 0; //get in reverse order $($('tbody tr', ultimo).get().reverse()).each(function(i, tr){ if (ultimo.height() > maxtrpxperpage) { $(tr).remove(); numtrsremovedfromcurrent++; } else { return false; } }); curtbltrscount = curtrscount - numtrsremovedfromcurrent; $('tbody tr', copy).each(function(i, tr){ if (i < curtbltrscount) { $(tr).remove(); } }); if (copy.find("td").length > 0) //don't insert a table with only a header { copy.insertAfter(ultimo); $("<div style='page-break-before:always'>Page " + (++pageno) + "</div>").insertAfter(ultimo); /* var heights = $.map( ultimo.find("tr"), function(el){ return $(el).outerHeight() + "|" + $(el).find("td").eq(1).text() + "/" + $(el).find("td").height() }).join(", "); $("<div style='font-family: sans-serif;font-size:15px;page-break-before:always'>blosah" + trlength + ", heights: " + heights + "<br>debugmsg: " + debugmessage + "--trs:" + ultimo.find("tr").length + "; window height: " + $(window).height() + "; document height: " + $(document).height() + "; table height: " + ultimo.height() + "; table width: " + ultimo.width() + "</div>").insertAfter(ultimo); */ } //copy.css('page-break-before', 'always'); ultimo = copy; trsleft -= curtbltrscount; } }); }); </script> </head> <body> <table class="splitForPrint" ><thead><tr><th>Header1###<th>Header2</th><th>Another header here</th></tr></thead> <tbody> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> <tr> <td>HDK 0 ksdTkskdjf Yte</td> <td>Hkekrulc=kS kdkurlkREK TSDNBKS LEKFLS =58349</td> <td>TyikmeskkVkslkjdsk ^ YIE</td> </tr> <tr> <td>Vaslkjds</td> <td>Xdk ks</td> <td>LE,X</td> </tr> <tr> <td>TT EESE23 4443</td> <td>TIE -;Nksj kerkdVkm</td> <td>Ekjs dksk TkdskX W5 TOI DKSJDFDKSLK DKSLK32</td> </tr> </tbody></table> </body>
Monday, August 20, 2012
Multi-App WSP Install.bat
@echo Deploy my.package.wsp :usage - install.bat url1 url2 ... @echo off if "%1" == "" goto NoInputErrorMessage setlocal set SPAdminTool=%CommonProgramFiles%\Microsoft Shared\web server extensions\12\BIN\stsadm.exe @echo on "%SPAdminTool%" -o addsolution -filename my.package.wsp "%SPAdminTool%" -o execadmsvcjobs "%SPAdminTool%" -o deploysolution -name "my.package.wsp" -immediate -allowGacDeployment -allowCasPolicies -force "%SPAdminTool%" -o execadmsvcjobs @echo off :LOOP IF "X%1" == "X" GOTO LOOPDONE echo Deploying solution to %1 @echo on "%SPAdminTool%" -o activatefeature -name myappfeature -url %1 @echo off SHIFT GOTO LOOP :LOOPDONE pause echo The batch file is complete. GOTO ENDFINAL :NoInputErrorMessage @ECHO Please enter these arguments: Application URLs separated by spaces @echo Sample command: Install.bat https://myapp1 https://myapp2 :ENDFINAL
Wednesday, August 15, 2012
Get Matching DLLs in VS Solution
Option Explicit ' need args for (0) SolutionDir (1) ilmerge executable (2) .snk file (3) /ver (4) output dll (5) Solution Project dir '(6) primary assembly file name e.g. "mylib.dll" (7) pubkey string of target DLLs e.g. "abcd123456787651" 'Ex: c:\Temp\>CreateMABat.vbs "C:\MySolution\" "c:\ilmerge\ilmerge.exe" "C:\MySolution\MyMainProject\MyNamespace.snk" 1.0.0.0 "c:\MySolution\MyMainProject\Dlls\CombinedLibrary.dll" "c:\MySolution\MyMainProject\" MyFirstDep.dll abcd123456787651 Dim args, pubKeyStr, matchingDLLs, objFSO, objShell, DictDlls Dim oMergeBat Dim oFS Set args = WScript.Arguments pubKeyStr = args(7) matchingDLLs = GetNewDllsThatMatchKey (args(0), pubKeyStr, args(6)) Set oFS = CreateObject("Scripting.FileSystemObject") Set oMergeBat = oFS.CreateTextFile(args(5) + "MergeAssemblies.bat", true) oMergeBat.WriteLine("@ECHO OFF") oMergeBat.WriteLine("@ECHO This script is generated by createMergeAssemblies.vbs") oMergeBat.WriteLine("") oMergeBat.WriteLine("@ECHO ...starting the merge program") oMergeBat.WriteLine("@ECHO ...") oMergeBat.WriteLine("@ECHO ...") oMergeBat.WriteLine("") oMergeBat.WriteLine("""" + args(1) + """ /ndebug /t:library /keyfile:""" + args(2) + """ /ver:" + args(3) + " /out:""" + args(4) + """ " + matchingDLLs) oMergeBat.WriteLine("") oMergeBat.WriteLine("@ECHO ...merging process complete") oMergeBat.WriteLine("") oMergeBat.WriteLine("Pause") 'WScript.Echo result ' given a root directory find all .dlls in subdirectories (exclude the root directory) ' for each dll found ' get its public key ' if it matches a pubkeyparamStr ' check dllsdict for key matching its filename ' if not found insert it ' if found ' compare its last modified date against existing file found ' if newer, replace dict entry Function GetNewDllsThatMatchKey(ByVal filePath, ByVal snKey, ByVal firstDll) Dim i, a, resultStr Set dictDlls = CreateObject("Scripting.Dictionary") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objShell = WScript.CreateObject("WScript.Shell") GetDictOfDlls filePath, "DLL" resultStr = """" & dictDlls.Item(firstDll) & """" dictDlls.Remove(firstDll) a = dictDlls.Keys For i=0 to dictDlls.Count-1 resultStr = resultStr & " """ & dictDlls.Item(a(i)) & """" ' WScript.Echo a(i) ' WScript.Echo dictDlls.Item(a(i)) Next GetNewDllsThatMatchKey = resultStr End Function Sub GetDictOfDlls(ByVal strDirectory, ByVal strExtSought) Dim objFolder, objSubFolder, objFile, filePubKey, objKeyFile Set objFolder = objFSO.GetFolder(strDirectory) objShell.CurrentDirectory = strDirectory For Each objFile in objFolder.Files ' WScript.Echo objFile.Path If Right(Ucase(objFile.Path),Len(strExtSought)+1) = "." & strExtSought Then filePubKey = GetFilePubKeyStr(objFile.Name) If pubKeyStr = filePubKey Then If dictDlls.Exists(objFile.Name) = True Then 'WScript.Echo "Exists " & objFile.Path Set objKeyFile = objFSO.GetFile(dictDlls.Item(objFile.Name)) 'WScript.Echo "date is " & objKeyFile.DateLastModified & " compared to " & objFile.DateLastModified If objKeyFile.DateLastModified < objFile.DateLastModified Then dictDlls.Item(objFile.Name) = objFile.Path End If Else dictDlls.Add objFile.Name, objFile.Path End If 'WScript.Echo filePubKey End If End If Next For Each objSubFolder in objFolder.SubFolders GetDictOfDlls objSubFolder.Path, strExtSought Next End Sub Function GetFilePubKeyStr(ByVal fileName) dim snExe, snCmd, fullCmd, strLine, objExecObject snExe = """C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\sn.exe""" snCmd = "cmd /c """ & snExe & """ -T " fullCmd = snCmd & fileName Set objExecObject = objShell.Exec(fullCmd) Do While Not objExecObject.StdOut.AtEndOfStream strLine = objExecObject.StdOut.ReadLine() 'Wscript.Echo strLine If InStr(strLine, "Public key token is ") then GetFilePubKeyStr = Right(strLine,16) 'Wscript.Echo Right(strLine,16) end if Loop Do While Not objExecObject.StdErr.AtEndOfStream Wscript.Echo objExecObject.StdErr.ReadLine() Loop End Function
Monday, July 30, 2012
Code DataGridView with Drop-downs from DataTable
This is how to create a DataGridView in code from a DataTable and featuring dropdown columns. Simply create a new Windows Form project and replace the form.cs code with the following:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication2 { public partial class Form1 : Form { BindingSource bindingsource1 = new BindingSource(); BindingSource productbs = new BindingSource(); System.Windows.Forms.DataGridView dataGridView1; DataTable dt; public Form1() { dt = new DataTable(); var dcblah = new DataColumn("blah"); dt.Columns.Add(dcblah); dt.Columns.Add(new DataColumn("2")); DataRow dr = dt.NewRow(); dr["blah"] = "bii"; dr["2"] = "boo"; dt.Rows.Add(dr); DataRow drd2 = dt.NewRow(); drd2["blah"] = "boo"; drd2["2"] = "bii"; dt.Rows.Add(drd2); this.SuspendLayout(); MyInitializeComponent(); InitializeComponent(); dataGridView1.AutoGenerateColumns = false; var dtp = new DataTable(); dtp.Columns.Add(new DataColumn("Product_name")); dtp.Columns.Add(new DataColumn("blah")); var dr1 = dtp.NewRow(); dr1["blah"] = "boo"; dr1["Product_name"] = "a product boo"; var dr2 = dtp.NewRow(); dr2["blah"] = "bii"; dr2["Product_name"] = "a xxproduct xxboo"; dtp.Rows.Add(dr1); dtp.Rows.Add(dr2); productbs.DataSource = dtp; dataGridView1.DataSource = bindingsource1; bindingsource1.DataSource = dt; foreach (DataColumn dc in dt.Columns) { ((DataGridViewComboBoxColumn)dataGridView1.Columns[dc.ColumnName]).DataPropertyName = dc.ColumnName; ((DataGridViewComboBoxColumn)dataGridView1.Columns[dc.ColumnName]).DataSource = productbs; ((DataGridViewComboBoxColumn)dataGridView1.Columns[dc.ColumnName]).DisplayMember = "Product_name"; ((DataGridViewComboBoxColumn)dataGridView1.Columns[dc.ColumnName]).ValueMember = "blah"; } this.Controls.Add(dataGridView1); } private void MyInitializeComponent() { this.dataGridView1 = new System.Windows.Forms.DataGridView(); foreach (DataColumn dc in dt.Columns) { var col = new DataGridViewComboBoxColumn(); col.HeaderText = dc.ColumnName; col.Name = dc.ColumnName; dataGridView1.Columns.Add(col); } ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.dataGridView1.Location = new System.Drawing.Point(22, 97); this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.Size = new System.Drawing.Size(240, 150); this.dataGridView1.TabIndex = 0; } private void Form1_Load(object sender, EventArgs e) { } } }
Subscribe to:
Posts (Atom)