VB multiline string as XML Literals

Probably known by most programmers, but I want to document it so I can find it myself later.

An easy way to create a multiline VB string is to create a xml literal and use the value

Dim myTest = <string>Here is a multi
line string that I want to use in
some other code.  It
helps the readability and
cut and paste functionality.
Even if this is a poor example
</string>

Dim strInside as string = myTest.value

SearchServer2008Express Search Webservice

I was working on calling the Search Server 2008 Express search webservice from Powershell.  I kept getting

 <ResponsePacket xmlns="urn:Microsoft.Search.Response"><Response domain=""><Status>ERROR_NO_RESPONSE</Status><DebugErrorMessage>The search request was unable to connect to the Search Service.</DebugErrorMessage></Response></ResponsePacket>

I checked the user authorization, the webservice search status, even the WSDL.  

Turns out the URL for the SearchServer2008 search webservice was incorrect.  I was calling 
$URI= "http://ss2008/_vti_bin/spsearch.asmx?WSDL"
and it should have been
$URI= "http://ss2008/_vti_bin/search.asmx?WSDL"


Here is my sample powershell script:
# WSS Documentation http://msdn.microsoft.com/en-us/library/bb862916.aspx

$error.clear()

#Bad SearchServer2008Express Search URL 
$URI= "http://ss2008/_vti_bin/spsearch.asmx?WSDL"
#Good SearchServer2008Express Search URL 
$URI= "http://ss2008/_vti_bin/search.asmx?WSDL"

$search = New-WebServiceProxy -uri $URI -namespace WSS -class Search -UseDefaultCredential 

$queryXml = "<QueryPacket xmlns='urn:Microsoft.Search.Query' Revision='1000'>
  <Query >
    <SupportedFormats>
      <Format revision='1'>urn:Microsoft.Search.Response.Document.Document</Format>
    </SupportedFormats>
    <Context>
      <QueryText language='en-US' type='MSSQLFT'>SELECT Title, Path, Description, Write, Rank, Size FROM Scope() WHERE CONTAINS('Microsoft')</QueryText>
      <!--<QueryText language='en-US' type='TEXT'>Microsoft</QueryText> -->
    </Context>
  </Query>
</QueryPacket>"
 
$statusResponse = $search.Status()
write-host '$statusResponse:'  $statusResponse
 
$GetPortalSearchInfo = $search.GetPortalSearchInfo()
write-host '$GetPortalSearchInfo:'  $GetPortalSearchInfo
 
$queryResult = $search.Query($queryXml)
write-host '$queryResult:'  $queryResult
 
 

Runnin Framework 4.0 with Powershell

I had problems running scripts with Framework 4.0 assemblies I created.  The error I was getting was 
 
Add-Type : Could not load file or assembly 'file:///C:\myDLL.dll' or one of its depend
encies. This assembly is built by a runtime newer than the currently loaded run
time and cannot be loaded.
 
I had to add the supported framework to the powershell.exe.config file.
<supportedRuntime version="v4.0.30319"/>

I still had a problem running the assembly so I had to recompile and set "Generate serialization Assembly" to off.

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();