Thursday, December 14, 2017

jQuery AJAX call

                async: true,
                dataType: 'xml',
                url: URL,
                success: function (data) {
                    div.innerHTML = new XMLSerializer().serializeToString(data.documentElement);
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log("" + errorThrown);

Tuesday, August 2, 2016

Quick and easy way to consume a REST service

//Define URI
string uri = http://blah/blah/

//Define REST variable
string id = "someId";

//Create WebClient and consume REST service
string response = null;
using(WebClient client = new WebClient())
    response = client.UploadString(string.Format("{0}{1}", uri, id), "");

Friday, June 10, 2016

Dynamically stream image to webform

Dynamically stream image to Panel control in WebForm

1.) Convert Stream to byte[] buffer
byte[] buffer = new byte[pd.Stream.Length];
pd.Stream.Read(buffer, 0, buffer.Length);

2.) Dynamically create Image control and set the ImageURL to the buffer
System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
img.ImageUrl = "data:image/tiff;base64," + Convert.ToBase64String(content, 0, content.Length);

 3.) Add Image control to the Panel


Tuesday, April 19, 2016

Iterate through Linq groups

Use IGrouping to iterate through the groups made by the Linq group

public static Dictionary<string, List<Request>> SplitRequestsByHeader(List<Request> requests)
var ordRequests = new Dictionary<string, List<Request>>();

var groups =
from r in ordRequests
group r by string.Format("{0}{1}{2}{3}", r.DistrictId, r.CustomerId, r.UnitId, r.OrderType) into grp
orderby grp.Key
select grp;

//Note: instead of iterating, could convert directly to Dictionary
//ordRequests = groups.ToDictionary(group => group.Key, group => group.ToList());

//Iterate each order within each group
foreach (IGrouping<string, Request> group in groups)
List<Request> ordGroup = new List<Request>();

foreach (var r in group)



                ordRequests.Add(group.Key, ordGroup);

return ordRequests;

Monday, February 1, 2016

How to GAC in Win8

In .net 4.0 Microsoft removed the ability to add DLLs to the Assembly simply by dragging and dropping into C:\Windows\assembly\.
Instead you need to use gacutil.exe, or create an installer to do it.

To use gacutil:
Start -> programs -> Microsoft Visual studio 2010 -> Visual Studio Tools -> Visual Studio Command Prompt (2010)
Then use these commands to uninstall and Reinstall respectively. Note I did NOT include .dll in the uninstall command.
gacutil /u myDLL
gacutil /i "C:\Program Files\Custom\myDLL.dll"

To use Gacutil on a non-development machine you will have to copy the executable and config file from your dev machine to the production machine. It looks like there are a few different versions of Gacutil. The one that worked for me, I found here:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\gacutil.exe C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\gacutil.exe.config
Copy the files here or to the appropriate .net folder;
Then use these commands to uninstall and reinstall respectively
"C:\Users\BHJeremy\Desktop\Installing to the Gac in .net 4.0\gacutil.exe" /u "myDLL"
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\gacutil.exe" /i "C:\Program Files\Custom\myDLL.dll"

Wednesday, November 18, 2015

Assist with debugging .NET application

To assist with debugging any peculiar behavior with code in Visual Studios, use the Microsoft Service Trace Viewer.

1.) Create a trace file - c:\logs\Traces.svclog

2.) Add diagnostics configuration section to the config file
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
          <add name="traceListener"
              initializeData="c:\logs\Traces.svclog"  />

3.) Run the application to produce the behavior and check the log file for assistance.

Wednesday, July 29, 2015

XSLT for converting DataSet to JSON

<xsl:stylesheet version="1.0"

  <xsl:output method="text" indent="no" omit-xml-declaration="yes" />
  <xsl:template match="NewDataSet">
    "Jobs": [
        <xsl:apply-templates select="Table"/>
  <xsl:template match="Table">
            "id": "<xsl:value-of select="jobid"/>",
            "title": "<xsl:value-of select="jobtitle"/>",
                "address": "<xsl:value-of select="jobaddress"/>",
                "city": "<xsl:value-of select="jobcity"/>",
                "state": "<xsl:value-of select="jobstate"/>",
                "zip": "<xsl:value-of select="jobzip"/>"
            "group": {
                "groupcode": "<xsl:value-of select="jobgroup"/>",
                "description": "<xsl:value-of select="jobgroupdescription"/>"
            "otherinformation": "<xsl:value-of select="otherinformation"/>",
            "payload": "<xsl:value-of select="payload"/>"