set jqueryUI ThemeRoller cookie

Seems to me that all users prefer a different color scheme for the web apps they work on.  With jQueryUI, the themes are available and can be chosen with the themeswitcher gadget.  Howerver, out of the box the chosen them only lasts as long as the session.  I wanted to change it to last longer.  There are some examples on the web of modifying the jqueryUI code, but I found a simpler fix. Change the jqueryUI cookie expire date

  <script>
 
  $(document).ready(function(){
   
    $('#switcher').themeswitcher(
    {
    onSelect: function(){
     $.cookie('jquery-ui-theme',$.cookie('jquery-ui-theme'),{ expires: 7 });
     }
    });
   
    alert("Current Theme:" + $.cookie('jquery-ui-theme'));
  });
  </script>

jqGrid inline afterSave event

A quick note on the inline afterSave event in jqgrid 4.3.1

I was trying to refresh the grid after adding a row using the inlineNav add row button.  I couldn't fire the afterSave method to refresh the grid.  Turns out that onSuccess has to be true before afterSave is fired.

{ name:

'EditOptions', index: 'EditOptions', hidden: false, width: 80

,formatoptions: { keys:

false, editbutton: true, delbutton: true, onSuccess: true,afterSave:function(rowid){alert('afterSave'); subgrid.trigger("reloadGrid"); } }

, formatter:

'actions', search: false},

Good Luck

Powershell Emailing Strings as attachments

I was working on a project to send a html attachment in a powershell script.  I have the HTML string so all I want to do is create an attachment from the string.  Here's the code:

 

$SMTPserver = "mail.company.com"
$from = "from@company.com"
$to = "to@company.com"
$subject = "Test PS Attachment"
$emailbody = "test"
$attText = "The text of the attachment"
$attName = "Test.txt"

 
$mailer = new-object Net.Mail.SMTPclient($SMTPserver)
$msg = new-object Net.Mail.MailMessage($from, $to, $subject, $emailbody)
 
$att = [System.Net.Mail.Attachment]::CreateAttachmentFromString($attText,$attName)
 
 $msg.Attachments.Add($att)

$msg.IsBodyHTML = $false
$mailer.send($msg)

That should get you started.

BizTalk 2010 SMTP mailer

I checked the SMTP headers on an email sent from the Biztalk 2010 SMTP send port.

X-Mailer: Microsoft CDO for Windows 2000

Really?  CDO Really?

IIS 7 URL Rewriting

I was working on a MVC3 project using jQuery to populate a text input in an iframe element from the parent.

The catch is that the iframe source is on a different domain.

When I first tried to do it, the javascript gave me the Permission Denied error for trying to access the iframe document in a different domain.

If the domain of the parent and iframe child are the same this Permission Denied error will not be encountered.  To get the iframe domain the same as the parent I needed to use a proxy to fetch the page from the remote site, change the domain and display it in the iframe.  Also the interactions in the iframe need to go back to the remote site.

To get this to work I downloaded the IIS URL Rewrite Module http://www.iis.net/download/URLRewrite

I had to create some rewriting rules to do the proxy.  This blog post
http://blogs.iis.net/carlosag/archive/2010/04/01/setting-up-a-reverse-proxy-using-iis-url-rewrite-and-arr.aspx
has a good description of how to create the rules.

jqGrid Row Edit Buttons

I've been working with the jqgrid and have been really impressed with the ease of use.  One issue I was having was with the action buttons on the row.  If a new row is selected, the action buttons wouldn't toggle back.  I had to toggle them myself in the onSelectRow function.

Here is a sample jqgrid based on the jqgrid samples http://www.trirand.com/blog/jqgrid/jqgrid.html

 

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
        <link href="/Content/Site.css" rel="stylesheet" type="text/css" />
 
        <link href="/Content/jquery-ui-1.8.7.css" rel="stylesheet" type="text/css" />
    <link href="/Content/ui.jqgrid.css" rel="stylesheet" type="text/css" />
    <link href="/Content/ui.multiselect.css" rel="stylesheet" type="text/css" />
 
 
<script src="/Scripts/jquery-1.6.1.min.js" type="text/javascript"></script>
    <script src="/Scripts/modernizr-1.7.min.js" type="text/javascript"></script>

    <script src="/Scripts/grid.locale-en.js" type="text/javascript"></script>
<script src="/Scripts/jquery.jqGrid.min.js" type="text/javascript"></script>

</head>
<body>
<script type="text/javascript">
    jQuery(document).ready(function () {

var lastsel2
jQuery("#rowed5").jqGrid({
 datatype: "local",
 height: 250,
    colNames:['ID Number','Name', 'Stock', 'Ship via','Notes','Edit'],
    colModel:[
     {name:'id',index:'id', width:90, sorttype:"int", editable: true},
     {name:'name',index:'name', width:150,editable: true,editoptions:{size:"20",maxlength:"30"}},
     {name:'stock',index:'stock', width:60, editable: true,edittype:"checkbox",editoptions: {value:"Yes:No"}},
     {name:'ship',index:'ship', width:90, editable: true,edittype:"select",editoptions:{value:"FE:FedEx;IN:InTime;TN:TNT;AR:ARAMEX"}},
     { name: 'note', index: 'note', width: 200, sortable: false, editable: true, edittype: "textarea", editoptions: { rows: "2", cols: "10"} },
       { name: '', index: '', width: 80, formatoptions: { keys: false, editbutton: true, delbutton: true }, formatter: 'actions' } 
    ],
 onSelectRow: function(id){
  if(id && id!==lastsel2){
      jQuery('#rowed5').jqGrid('restoreRow', lastsel2);

      $("tr#" + lastsel2 + " div.ui-inline-edit, " + "tr#" + lastsel2 + " div.ui-inline-del", "#rowed5").show();
      $("tr#" + lastsel2 + " div.ui-inline-save, " + "tr#" + lastsel2 + " div.ui-inline-cancel", "#rowed5").hide();
  // Let the action buttons set the edit row
  // jQuery('#rowed5').jqGrid('editRow',id,true);
   lastsel2=id;
  }
 },
 editurl: "server.php",
 caption: "Input Types"

});
var mydata2 = [
  {id:"12345",name:"Desktop Computer",note:"note",stock:"Yes",ship:"FedEx"},
  {id:"23456",name:"Laptop",note:"Long text ",stock:"Yes",ship:"InTime"},
  {id:"34567",name:"LCD Monitor",note:"note3",stock:"Yes",ship:"TNT"},
  {id:"45678",name:"Speakers",note:"note",stock:"No",ship:"ARAMEX"},
  {id:"56789",name:"Laser Printer",note:"note2",stock:"Yes",ship:"FedEx"},
  {id:"67890",name:"Play Station",note:"note3",stock:"No", ship:"FedEx"},
  {id:"76543",name:"Mobile Telephone",note:"note",stock:"Yes",ship:"ARAMEX"},
  {id:"87654",name:"Server",note:"note2",stock:"Yes",ship:"TNT"},
  {id:"98765",name:"Matrix Printer",note:"note3",stock:"No", ship:"FedEx"}
  ];
for(var i=0;i < mydata2.length;i++)
 jQuery("#rowed5").jqGrid('addRowData',mydata2[i].id,mydata2[i]);

 });
 </script>
 <table id="rowed5"></table>

</body>
</html>
 

MVC3 JSON Error

I was working on a MVC3 project with jqGrid using JSON.  The data was created using EF4 Code First.  Took me a while to hook up the grid and actually having it post back to the server to retrieve the JSON.  I was having issues with my int ID column not formatting to JSON. 

LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.

StackOverflow had some responses to use

SqlFunctions.StringConvert((double)products.ProductID)

Then I received a different error

The specified method 'System.String StringConvert(System.Nullable`1[System.Double])' on the type 'System.Data.Objects.SqlClient.SqlFunctions' cannot be translated into a LINQ to Entities store expression.

What I ended up doing is creating a list of the products and then looping through them

var products = from product in db.Products
               select product;
              
var prodList = products.ToList();
 

 

 

Google Toolbar 7 Buttons

My computer installed the latest google toolbar and everything was screwed up.  Fonts and colors for searching?? Missing toolbar buttons??  I guess I should work at google where getting nothing done is working.

Anyway I found a cryptic blog post about the "missing buttons" (http://www.google.com/support/toolbar/bin/answer.py?hl=en&answer=1247010).  Apparently they did it for my own good and to clean up the toolbar.  Under "More >>" the buttons are there.  Click on them and they return to the toolbar.

Thanks for letting us know about the changes Google.

Powershell FTP

I've been looking for a replacement for my powershell script used to ftp files.  It currently uses the Windows ftp.exe application with a command file.  Well the script has been causing problems and files have been truncated or lost.  I decided to look into a replacement.

I tried ftpwebrequest but when moving multiple files the login happens over and over.

I found Alex FTPS Client on codeplex at http://ftps.codeplex.com/  Seems to do what I needed. 

Here is a Powershell script to use it to connect, list contents, get the files and put the files

 
add-type -path "C:\AlexPilotti.FTPS.Client.dll"

$ftpServer = "ftp.someftp.com"
$username ="validUser"
$password ="myPassword"
$localToFTPPath = "C:\ToFTP"
$localFromFTPPath = "C:\FromFTP"
$remotePickupDir = "/Inbox"
$remoteDropDir = "/Outbox"
$SSLMode = [AlexPilotti.FTPS.Client.ESSLSupportMode]::ClearText

$ftp = new-object "AlexPilotti.FTPS.Client.FTPSClient"
$cred = New-Object System.Net.NetworkCredential($username,$password)

"Connect"
$ftp.Connect($ftpServer,$cred,$SSLMode)
"Get DirectoryList"
$ftp.GetDirectoryListUnparsed()

"Get Files"
$ftp.SetCurrentDirectory($remotePickupDir)
$ftp.GetFiles($localFromFTPPath, $false)

"Put Files"
$ftp.PutFiles($localToFTPPath, $remoteDropDir, "*.edi", [AlexPilotti.FTPS.Client.EPatternStyle]::Wildcard, $false, $Null)

"Done"

W006.15 isp or T-mobile Network Error.

I just bought a new T-Mobile G2.  I wanted to turn on Wifi calling but kept receiving "W006.15 isp or T-mobile Network Error" and asking me to register. 

After doing some research I looked at my cable modem/router logs and config.  There were fragmented packets originating from the phone and the incoming fragmented packets were blocked.  I disabled the "Block fragmented packets" setting and the phone was able to connect for Wifi calling