<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Chris Cooper</title>
    <description>The latest articles on DEV Community by Chris Cooper (@chriscooper01).</description>
    <link>https://dev.to/chriscooper01</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F128742%2F579255a3-d31b-498c-baa4-df1a0dfc8e64.jpeg</url>
      <title>DEV Community: Chris Cooper</title>
      <link>https://dev.to/chriscooper01</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chriscooper01"/>
    <language>en</language>
    <item>
      <title>Full input box with Dynamic Placeholder appear on the side </title>
      <dc:creator>Chris Cooper</dc:creator>
      <pubDate>Fri, 12 Jun 2020 10:55:31 +0000</pubDate>
      <link>https://dev.to/chriscooper01/full-input-box-with-dynamic-placeholder-appear-on-the-side-3kf</link>
      <guid>https://dev.to/chriscooper01/full-input-box-with-dynamic-placeholder-appear-on-the-side-3kf</guid>
      <description>&lt;p&gt;This is a simple but effective way of making your input box's look good and have the place holder appear as a label, when the input box has data within&lt;/p&gt;

&lt;p&gt;I have created a simple example, using .NetCore Razor pages.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The input box should look like below&lt;/strong&gt;&lt;br&gt;
When the input box is empty&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_9gS7Wc6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0uw3asl2k6jsgt88f2ux.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_9gS7Wc6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0uw3asl2k6jsgt88f2ux.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When data inputted&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--k_OPOreV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gjeo4mlcchv02maf8uro.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k_OPOreV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gjeo4mlcchv02maf8uro.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Example&lt;/strong&gt;&lt;br&gt;
Full example of code can be found within the below GIT repo&lt;br&gt;
&lt;a href="https://github.com/chriscooper01/InputBoxLabel"&gt;https://github.com/chriscooper01/InputBoxLabel&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  The code
&lt;/h1&gt;

&lt;p&gt;Below is the code broken down into its raw elements.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Input box.
&lt;/h2&gt;

&lt;p&gt;As you can see you have a simple label and Text box. The label is set the "InputEnterLabel" css  class as default.&lt;br&gt;&lt;br&gt;
The input box is set "InputBox" css class as default with the onkeyUp JS function call inputBoxPlaceHolder, which will pass the controller into the function.  There is as well a data attribute added for the place holder to hold the label content.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"row col-sm-12 col-md-12 col-lg-12 InputBoxRow "&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
     @Html.LabelFor(Model =&amp;gt; Model.INPUTRecord, new { @class = "InputEnterLabel" })
     @Html.TextBoxFor(Model =&amp;gt; Model.INPUTRecord, new { @class = "InputBox", @placeholder = "Place holder inside input",  onkeyup = "inputBoxPlaceHolder(this)", data_placholder = "Outside PC:" })

&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Java script side
&lt;/h2&gt;

&lt;p&gt;Now here I have two main call, one to be called on the document load, so it knows to set the label in the correct location and the call that is done on the Key up of the input box.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;checkInputBoxPlacholderNeeded&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Looking for input box&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;inputs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.InputBox&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Input box's found: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;inputs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;inputs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;inputBoxPlaceHolder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;inputBoxPlaceHolder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputBox&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;labelText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputBox&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputBox&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;hasClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;InputEntered&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputBox&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;addClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;InputEntered&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nx"&gt;labelText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;label[for=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;inputBox&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;labelText&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;InputEnterLabelViewable&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;labelText&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputBox&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;placholder&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputBox&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;removeClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;InputEntered&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;labelText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;label[for=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;inputBox&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;labelText&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;removeClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;InputEnterLabelViewable&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you want the input box's to set dynamically on page load add the below script to the page JS file.  This will call the checkInputBoxPlacholderNeeded function to look for the input box's and check if they have data or not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;ready&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="c1"&gt;//same as: $(function() { &lt;/span&gt;

    &lt;span class="nx"&gt;checkInputBoxPlacholderNeeded&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="c1"&gt;//$('#MergeStart').hide();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  CSS
&lt;/h2&gt;

&lt;p&gt;Below is simple CSS which, make my Input box's and label look like they do.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.InputBoxRow&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;padding-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;max-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;55px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;0px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="nc"&gt;.InputEntered&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;padding-left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt; &lt;span class="cp"&gt;!important&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;100%&lt;/span&gt; &lt;span class="n"&gt;-&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cp"&gt;!important&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;100%&lt;/span&gt; &lt;span class="n"&gt;-&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cp"&gt;!important&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin-left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt; &lt;span class="cp"&gt;!important&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.InputBox&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;min-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;max-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;12px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;12px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#e6e1e1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;600&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding-left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding-right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.InputEnterLabel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;visibility&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;hidden&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;z-index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;min-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;max-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#aea9a9&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;500&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding-left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;x-small&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.InputEnterLabelViewable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;visibility&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;visible&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#e6e1e1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt; &lt;span class="cp"&gt;!important&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt; &lt;span class="cp"&gt;!important&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>css</category>
      <category>javascript</category>
      <category>inputbox</category>
      <category>label</category>
    </item>
    <item>
      <title>Breadcrumbs within Razor page .Net Core</title>
      <dc:creator>Chris Cooper</dc:creator>
      <pubDate>Sat, 18 Apr 2020 19:37:37 +0000</pubDate>
      <link>https://dev.to/chriscooper01/breadcrumbs-within-razor-page-net-core-5f4c</link>
      <guid>https://dev.to/chriscooper01/breadcrumbs-within-razor-page-net-core-5f4c</guid>
      <description>&lt;p&gt;I'm still quite new to Razor pages (not mvc) and wanted a Breadcrumb navigation bar on my pages, which was created dynamically. I looked around but in the end I created my own and this is how I did it. There is a full example of my solution on a .net core razor page solution on git.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Breadcrumb creation
&lt;/h1&gt;

&lt;p&gt;This is created within a class that will be inherited on the pagemodel class.  This is broken down into many smaller part to make it easier.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Validating the Request
&lt;/h2&gt;

&lt;p&gt;Firs you need to make sure the Request has a path and a query string, before you start looking at making the bread crumbs&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public void Validate()
    {
        currentQuery = String.Empty;
        currentPath = String.Empty;
        referers = this.Request.Headers["Referer"].ToList(); ;
        if (this.Request.Path.HasValue)
            currentPath = this.Request.Path.Value.Replace("/", String.Empty);
        if (this.Request.QueryString.HasValue)
            currentQuery = this.Request.QueryString.Value;

    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Get current bread crumbs
&lt;/h2&gt;

&lt;p&gt;This logic uses a session with a JSON object, containing all needed data for my breadcrumbs&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    private  void getCurrentBreadCrumbs()
    {
        var sessionString = HttpContext.Session.GetString("BreadCrumbs");
        breadCrumbs = new List&amp;lt;DataClassesLibrary.BreadCrumbDataClass&amp;gt;();
        if (String.IsNullOrWhiteSpace(sessionString) || sessionString.Equals("[]"))
            return;

        breadCrumbs = (List&amp;lt;DataClassesLibrary.BreadCrumbDataClass&amp;gt;)HelperLibrary.JsonStringHelper.GetObject(sessionString, breadCrumbs.GetType());

    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Setting new bread crumb
&lt;/h2&gt;

&lt;p&gt;Now I have my current and a valid request object, I can see if I need to set a new bread crumb for the current page.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    private  void setBreadCrumbs()
    {
        if (referers.Count &amp;gt; 0)
        {
            var urlValue = referers[0].ToString();
            var urlElements = urlValue.Split("/").ToList();
            var hostLocation = urlElements.IndexOf(this.Request.Host.Value);
            if (urlElements.Count() &amp;gt; hostLocation)
            {
                var razorPageURL = urlElements[hostLocation + 1];
                var razorPage = razorPageURL.Split("?");
                if (razorPage.Count() &amp;gt; 0)
                {
                    var data = new DataClassesLibrary.BreadCrumbDataClass();
                    data.Key = razorPage[0].ToString();
                    //Make sure I'm not adding the page back in I have removed
                    if (crumbRemoved.FirstOrDefault(x =&amp;gt; x.Equals(data.Key)) != null)
                        return;

                    if (setCurrentAsDisabled(data.Key))                        
                        return;//Do not set if already exists


                    if (razorPage.Count().Equals(2))
                    {                            
                        data.Parameters = setParameters(razorPage[1]);
                    }
                    breadCrumbs.Add(data);
                }

            }                
        }
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Set the session
&lt;/h2&gt;

&lt;p&gt;Because I use a session with a JSON object, to hold my current breadcrumbs, I will set the session with the new data.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    private void setSession()
    {
        HttpContext.Session.Set("BreadCrumbs", System.Text.Encoding.UTF8.GetBytes(HelperLibrary.JsonStringHelper.GetString(breadCrumbs)));
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;
  
  
  Creating the HTML breadscrumb
&lt;/h1&gt;

&lt;p&gt;This goes through my Bread crumbs List object and creates the required simple HTML.&lt;/p&gt;
&lt;h2&gt;
  
  
  Navigation bar
&lt;/h2&gt;

&lt;p&gt;This is the main method that creates the navigation bar&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public string SetNavString(List&amp;lt;DataClassesLibrary.BreadCrumbDataClass&amp;gt; crumbs)
    {
        if (crumbs == null || crumbs.Count.Equals(0))
            return String.Empty;

        var nav = new StringBuilder();
        nav.AppendLine("&amp;lt;nav aria-label=\"breadcrumb\"&amp;gt;");
        nav.AppendLine("&amp;lt;ol class=\"breadcrumb\"&amp;gt;");

        foreach (var crumb in crumbs)
            nav.AppendLine(setLinkItem(crumb));

        nav.AppendLine("&amp;lt;/ol&amp;gt;");
        nav.AppendLine("&amp;lt;/nav&amp;gt;");
        return nav.ToString();
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Creating the linked item
&lt;/h2&gt;

&lt;p&gt;This is how I have created the linked item, within the Navigation bar&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    private static string setLinkItem(DataClassesLibrary.BreadCrumbDataClass crumb)
    {
        var item = new StringBuilder();
        if (!crumb.Current)
        {
           item.AppendLine("&amp;lt;li class=\"breadcrumb-item \"&amp;gt;");
           item.AppendLine(String.Format("&amp;lt;a href=\"{0}{1}\" &amp;gt;{0}&amp;lt;/a&amp;gt;", crumb.Key, setLinkItemParemeters(crumb)));
        }
        else
        {
            item.AppendLine("&amp;lt;li class=\"breadcrumb-item active\" aria-current=\"page\"&amp;gt;");
            item.AppendLine(crumb.Key);
        }

        item.AppendLine("&amp;lt;/li&amp;gt;");
        return item.ToString();
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Setting parameters
&lt;/h2&gt;

&lt;p&gt;Setting the parameters for a linked item &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    private static string setLinkItemParemeters(DataClassesLibrary.BreadCrumbDataClass crumb)
    {
        if (crumb.Parameters == null || crumb.Parameters.Count.Equals(0))
            return String.Empty;

        var parameter = new List&amp;lt;string&amp;gt;();
        foreach (var p in crumb.Parameters)
        {
            parameter.Add(String.Format("{0}={1}", p.Key, p.Value));
        }

        return "?" + String.Join("&amp;amp;", parameter.ToArray());
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;
  
  
  Invoke the build
&lt;/h1&gt;

&lt;p&gt;Once you have inherited the build class you call the build or reset method on the OnGet method.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class FlagListModel : Pages.Extended.BreadCrumbsExtended
{

    public void OnGet()
    {
        SetBreadCrumbs();          

    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Bread crumbs extended class
&lt;/h2&gt;

&lt;p&gt;The SetBreadCrumbs method sits within the extended class and looks like below&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public  void SetBreadCrumbs()
    {   
        currentQuery = String.Empty;
        currentPath = String.Empty;
        referers = this.Request.Headers["Referer"].ToList(); ;
        if (this.Request.Path.HasValue)
            currentPath = this.Request.Path.Value.Replace("/", String.Empty);
        if (this.Request.QueryString.HasValue)
            currentQuery = this.Request.QueryString.Value;

        getCurrentBreadCrumbs();

        checkGoingBack();
        setBreadCrumbs();

        setCurrent();
        setSession();

        BreadCrumb = BreadCrumbsNavigationExtended.SetNavString(breadCrumbs);
        //Dispos
        currentQuery = String.Empty;
        currentPath = String.Empty;
        referers = null;
        breadCrumbs = null;
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Show the navigation bar&lt;/strong&gt;&lt;br&gt;
Now you have inherited and invoked the build, you want to show the navigation bar.  This is done simply by placing the single line.&lt;/p&gt;

&lt;p&gt;@Html.Raw(Model.BreadCrumb)&lt;/p&gt;

&lt;p&gt;Now you have inherited and invoked the build, you want to show the navigation bar.  This is done simply by placing the single line.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Full solution&lt;/strong&gt;&lt;br&gt;
The full solution can be found within my public GitHub repo.&lt;br&gt;
The SetBreadCrumbs logic is done on the Privacy page. The WipeBreadCrumbs logic is done on the index (home) page&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/chriscooper01/BreadCrumbs.git"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

</description>
      <category>net</category>
      <category>core</category>
      <category>razorpage</category>
      <category>breadcrumb</category>
    </item>
    <item>
      <title>WebAPI Post with Body parameters</title>
      <dc:creator>Chris Cooper</dc:creator>
      <pubDate>Mon, 21 Jan 2019 13:09:16 +0000</pubDate>
      <link>https://dev.to/chriscooper01/webapi-post-with-body-parameters-21be</link>
      <guid>https://dev.to/chriscooper01/webapi-post-with-body-parameters-21be</guid>
      <description>&lt;p&gt;The other day I needed to create a POST API (WebApi) for a third part to consume and return data, simple! Well it was not as simple as I first thought, as they were not able to hit my API and was getting the &lt;em&gt;"No HTTP resource was found that matches the request URI"&lt;/em&gt;. This was down to the way I had created my API and the way they were sending the POST data.&lt;br&gt;&lt;br&gt;
Normally I create PPOST WebAPI with the parameters in the method and you send the parameters in the URL. (&lt;em&gt;Get parameters&lt;/em&gt;) They were sending the parameters in the POST body not within the URL, so they were getting the error. So I needed to remove the parameters and get the parameters from the &lt;strong&gt;RequestContext&lt;/strong&gt;.    &lt;/p&gt;

&lt;p&gt;HTTP POST method&lt;br&gt;&lt;br&gt;
This is the &lt;strong&gt;POST&lt;/strong&gt; method with out any parameters and gets the request context out of the HTTP Post Request.&lt;br&gt;&lt;br&gt;
  &lt;/p&gt;
&lt;div class="runkit-element"&gt;
  &lt;code&gt;
    
  &lt;/code&gt;
  &lt;code&gt;
    [HttpPost]  
    public bool DeliveryReceipts()  
    {                        
        var value = this.Request.GetRequestContext();  

        getPostContent(Request.Content);  

        return true;  
    } 


  &lt;/code&gt;
&lt;/div&gt;
 &lt;br&gt;
Reading the context&lt;br&gt;&lt;br&gt;
Now that the context has been collected from the request. This method gets a string key\value for the parameters, sent in the request.&lt;br&gt;&lt;br&gt;
  &lt;div class="runkit-element"&gt;
  &lt;code&gt;
    
  &lt;/code&gt;
  &lt;code&gt;
    
 private async void getPostContent(HttpContent content)
 {
           DataClassesRequestParameterDataClass request = newDataClassesRequestParameterDataClass();
            var contentString = await content.ReadAsStringAsync();
            var contentElements = contentString.Split('&amp;amp;');  
        foreach(var element in contentElements)  
        {  
            var parameter = element.Split('=');  
            if(parameter.Count()&amp;gt;0)  
            {  
                setDataClass(parameter[0], parameter[1], ref request); 

            }//END if(parameter.Count()&amp;gt;0)  

        }//END foreach(var element in contentElements)  
}  


  &lt;/code&gt;
&lt;/div&gt;
 &lt;br&gt;
Collecting the value&lt;br&gt;&lt;br&gt;
This is a simple method that sets a veritable from the key found within the key\value string.&lt;br&gt;&lt;br&gt;
  &lt;div class="runkit-element"&gt;
  &lt;code&gt;
    
  &lt;/code&gt;
  &lt;code&gt;
    
private void setDataClass(string parameter, string value, ref 
 DataClassesRequestParameterDataClass request)
{
            switch(parameter.ToLower().Trim())
            {
                case "number":
                    request.Number = value;
                    break;
                case "userid":
                    request.UserId = value;
                    break;
                case "datetime":
                    request.DateTime = value;
                    break;
                case "status":
                    request.Status= value;
                    break;
            }
 }  


  &lt;/code&gt;
&lt;/div&gt;
 

&lt;p&gt;Summary&lt;br&gt;&lt;br&gt;
I've never used this technique of making post methods, but in away this seems a bit more secure than setting the parameters in the method, just simple because no one will know which parameter are needed to work the method.&lt;br&gt;&lt;br&gt;
I'm sure this wont be the last time, I use the logic for a POST method.&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>webapi</category>
      <category>httppost</category>
      <category>requestcontext</category>
    </item>
    <item>
      <title>Select query using an outer apply</title>
      <dc:creator>Chris Cooper</dc:creator>
      <pubDate>Wed, 16 Jan 2019 09:54:11 +0000</pubDate>
      <link>https://dev.to/chriscooper01/select-query-using-an-outer-apply-316i</link>
      <guid>https://dev.to/chriscooper01/select-query-using-an-outer-apply-316i</guid>
      <description>

&lt;p&gt;This is a simple example of using an SQL &lt;strong&gt;Outer apply&lt;/strong&gt; to create a select query that can create queryable custom sub fields.&lt;br&gt;&lt;br&gt;
Before being shown outer apply logic, I was using a temp tables and sub query. The sub table added the data required on the temp table and then I queried the temp table as needed. Now I can do it all in one simpler and quicker select query.  &lt;/p&gt;

&lt;p&gt;The simple query&lt;br&gt;&lt;br&gt;
This example is done on a user_extended table that is a Key and value pair logic, that acts as a dumping group for records that maybe used later. When a record is inserted and it contains the same key as a record in the DB table, the DB table record is disabled and this new record is made active.&lt;br&gt;&lt;br&gt;
The purpose of this it to check if the created date record is the active and is not disabled.  &lt;/p&gt;


&lt;div class="runkit-element"&gt;
  &lt;code&gt;&lt;/code&gt;
  &lt;code&gt;
SELECT   Parent.Username, ActiveDate,DisableDate FROM User AS Parent  OUTER APPLY
    (
        SELECT TOP 1
            MAX (CASE WHEN Child.Active= 1 AND Child.key = 'LastLoggedIn' THEN Child.DateOfCreation END) AS ActiveDate,
            MAX (CASE WHEN Child.Active = 0 AND Child.key = 'LastLoggedIn' THEN Child.DateOfCreation END) AS DisableDate
        FROM [Users_Extended] AS Child
        WHERE Child.UserId = Parent.Id
group by DateOfCreation
        ORDER BY Child.DateOfCreation DESC
    ) Child
WHERE Parent.key = 'LastLoggedIn' AND Parent.Active = 0 AND ActiveDate &amp;lt; DisableDate;
ORDER BY Parent.Id DESC
&lt;/code&gt;
&lt;/div&gt;
 


</description>
      <category>sql</category>
      <category>outerapply</category>
      <category>select</category>
    </item>
    <item>
      <title>Sending Data Objects to WebAPI in C#</title>
      <dc:creator>Chris Cooper</dc:creator>
      <pubDate>Tue, 15 Jan 2019 14:59:43 +0000</pubDate>
      <link>https://dev.to/chriscooper01/sending-data-objects-to-webapi-in-c-58i8</link>
      <guid>https://dev.to/chriscooper01/sending-data-objects-to-webapi-in-c-58i8</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F238w5jsvxm4agpuj3vjd.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F238w5jsvxm4agpuj3vjd.jpg" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a easy and reusable code that can be used to send data object to WebAPIs in C#. This code is an improvement to the code already posted on my blog.&lt;/p&gt;

&lt;p&gt;This now will work with Get and parameter webAPI action methods and you want to use data class on your side. The object will need parameters with the same name as the parameters of the API &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Invoking&lt;/strong&gt;&lt;br&gt;
This is the main method that would invoke the API logic. This needs the API full URL, API HTTP action type (GET/POST), return object type&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class JSONAPI 
{

    public static object Invoke(string url, string requestMethod, object dataObject, Type returnType)
    {
        object returnObject = null;

        callAPI(url, requestMethod, dataObject, returnType, updateStatus,  ref returnObject);

        return returnObject;
    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Calling the API&lt;/strong&gt;&lt;br&gt;
This is the main method that takes the parameter and return object &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    private static void callAPI(string url, string requestMethod, object dataObject,Type returnType, ref object returnObject)
    {

        try
        {

            HttpWebRequest request = null;
            FoundServices = true;

            createRequest(url, requestMethod, dataObject, ref request);

            if (request != null)
            {

                WebResponse webResponse = null;

                if (getReponse(request,updateStatus,  ref webResponse))
                {
                    updateStatus(SyncServiceTextResource.JSONDataDownloading, 0, ENUMS.MainProgressENUM.UpdateSecondary);

                    Stream webStream = webResponse.GetResponseStream();
                    using (StreamReader reader = new StreamReader(webStream))
                    {
                        using (var json = new Newtonsoft.Json.JsonTextReader(reader))
                        {
                            Newtonsoft.Json.JsonSerializer serializerJ = new Newtonsoft.Json.JsonSerializer();
                            updateStatus(SyncServiceTextResource.JSONDataConverting, 0, ENUMS.MainProgressENUM.UpdateSecondary);
                            returnObject = serializerJ.Deserialize(json, returnType);
                            updateStatus(SyncServiceTextResource.JSONDataConvertingCompleted, 0, ENUMS.MainProgressENUM.UpdateSecondary);
                            System.GC.Collect();
                        }//END using (var json = new Newtonsoft.Json.JsonTextReader(reader))
                    }//END using (StreamReader reader = new StreamReader(webStream))
                }//END if (getReponse(request,updateStatus,  ref webResponse))
            }//END if (request != null)

        }
        catch (Exception e)
        {

        }

    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Create the request&lt;/strong&gt;&lt;br&gt;
This is the method is used to take the parameter object and the GET OR POST type, with the URL to create the the required string to call the API.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     private static bool createRequest(string url, string requestMethod, object dataObject, ref HttpWebRequest request)
    {
        request = null;


        request = (HttpWebRequest)WebRequest.Create(url);

        request.Method = requestMethod;// "POST";
        request.ContentType = "application/json";
        string jsonDataString = setJSONString(dataObject);

        if (dataObject != null &amp;amp;&amp;amp; requestMethod.Equals("POST"))
        {

            request.ContentLength = jsonDataString.Length;
            request.Method = requestMethod;// "POST";
            request.ContentType = "application/json";
            //request.SendChunked = true;



            StreamWriter requestWriter = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);

            requestWriter.Write(jsonDataString);
            requestWriter.Close();
        }
        else
        {
            var jObj = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(jsonDataString);
            var query = String.Join("&amp;amp;",
                            jObj.Children().Cast()
                            .Select(jp =&amp;gt; jp.Name + "=" + HttpUtility.UrlEncode(jp.Value.ToString())));


            bool parameters = true;

            if (!parameters)
                url += "?" + jsonDataString;
            else
                url += "?" + query;


            request = (HttpWebRequest)WebRequest.Create(url);// +"?"+ query);


            request.Method = requestMethod;// "POST";
            request.ContentType = "application/json";


        }


        return request.HaveResponse;


    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Json string creation&lt;/strong&gt;&lt;br&gt;
This method takes the object and creates a JString for the object&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    private static string setJSONString(object dataObject)
    {
        var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
        serializer.MaxJsonLength = MAXJSONLENGTH;
        string jsonDataString = serializer.Serialize(dataObject);
        return jsonDataString;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Get response&lt;/strong&gt;&lt;br&gt;
This method will wait an x amount of time to make sure it has given the API enough time to response.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     private  static bool getReponse(HttpWebRequest request, ref WebResponse response)
    {
        bool responseCompleted = false;                       
        System.Timers.Timer tim = new System.Timers.Timer();
        tim.Interval = 2000;       
        timerElapsed = false;
        tim.Start();

        int milSeconWait = 500;//Start with 0.5 seconds wait
        int maxMilSeconWait = 120000;//MAX of 2 Mins
        int timesWaiting = 0;
        bool stillWaiting = false;
        while (!responseCompleted)
        {

            if (timerElapsed)
            {
               responseCompleted = false;
                break;
            }
            responseCompleted = webResponse.IsCompleted;
            if (responseCompleted)
            {
                break;
            }    
           timesWaiting++;

            Console.WriteLine("JSON GET REPSONE SLEEP AND WAIT: " + milSeconWait.ToString() + " Wait loop " + timesWaiting.ToString());
            System.Threading.Thread.Sleep(milSeconWait);
            milSeconWait = INITIALWAIT * timesWaiting;
        }

        if (responseCompleted &amp;amp;&amp;amp; webResponse.Result != null)
        {
            response = webResponse.Result;

        }
        tim.Stop();
        tim.Dispose();
        timerElapsed = false;          

        return responseCompleted;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Constant used&lt;/strong&gt;&lt;br&gt;
Below are the constants used through the full logic code &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    private const int MAXJSONLENGTH = int.MaxValue;
    protected static bool FoundServices;
    private static bool timerElapsed = false;
    private static bool secondAttempt;
    private const int INITIALWAIT = 500;//MIN 0.5 second wait
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;WebAPI Get Action side&lt;/strong&gt;&lt;br&gt;
To make sure the API will work with the above code will need the [FromUri] in the method call.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class SIMPLEController : ApiController
{

    [HttpGet]        
    public DataClasses.Returns.OBJECTCLASS GET([FromUri]DataClasses.Parameters.OBJECTCLASS parameter)
    {
        var watch = System.Diagnostics.Stopwatch.StartNew();

        DataClasses.Returns.OBJECTCLASS  returnObject new DataClasses.Returns.OBJECTCLASS ();

        //DO LOGIC

        return returnObject;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>c</category>
      <category>webapi</category>
      <category>json</category>
    </item>
    <item>
      <title>User roaming profile ClickOnce application restore</title>
      <dc:creator>Chris Cooper</dc:creator>
      <pubDate>Thu, 17 May 2018 15:45:16 +0000</pubDate>
      <link>https://dev.to/chriscooper01/user-roaming-profile-clickonce-application-restore-2io1</link>
      <guid>https://dev.to/chriscooper01/user-roaming-profile-clickonce-application-restore-2io1</guid>
      <description>

&lt;p&gt;I know Officially Click Once does not support User roaming profiles, but not support does not mean that you can create a work around and this is my work around.&lt;br&gt;&lt;br&gt;
My solution is an application that sits outside the Click once application in a safe modifiable area. I’m using the C:\ProgramData folder. This application then get invoked by the Click once application to make a backup copy of its binaries and the linked registration elements within the user’s registration data. Once completed it then takes a copy of the original short cut and add its own short cut to the user desktop. Now the user will use this application to invoke the original Click Once application.&lt;br&gt;&lt;br&gt;
When the solution is invoked, it will check if a recovery is needed and then invoked the original Click Once application.&lt;br&gt;&lt;br&gt;
Full example in the example application on my GitHub repo. Use it, improve it or just use it as an starting point  &lt;/p&gt;

&lt;p&gt;The application&lt;br&gt;&lt;br&gt;
This application is split into two main elements; backup and recovery. You’re initial Click once application will initialise the required data and then invoke the application in backup mode.&lt;br&gt;&lt;br&gt;
Within the backup mode is split into two elements; binaries and registration data. When it backup the binaries it finds the original short cut link for the user on the desktop and replaces it with a link to itself.&lt;br&gt;&lt;br&gt;
The user will use the new link to open the original click once application, but as the link has been changed to invoke the recovery application. The recovery application will check if the AppData and registration data is already present, if not it will restore these and then invoke the original application as a click once application.&lt;br&gt;&lt;br&gt;
&lt;em&gt;Full example in the example application on my &lt;a href="%E2%80%9D"&gt;GitHub repo&lt;/a&gt;. Use it, improve it or just use it as an starting point&lt;/em&gt;  &lt;/p&gt;

&lt;p&gt;Application data&lt;br&gt;&lt;br&gt;
First thing you need to initialise the recovery application from your original click once application. Below is an example code that shows what is needed.  &lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;  &lt;/div&gt;

&lt;p&gt;This data can be set from your initial click once application, using the simple code snippet below.  &lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;  &lt;/div&gt;

&lt;p&gt;Backup binaries&lt;br&gt;&lt;br&gt;
When the backup mode is invoked it will find the required application folders using &lt;strong&gt;ClickOnceLocation&lt;/strong&gt; and &lt;strong&gt;FolderStartsWith&lt;/strong&gt; value to find the required folders. These files are then copied to the &lt;strong&gt;RecoveryLocation&lt;/strong&gt; location. It will copy the folders in the same structure.&lt;br&gt;&lt;br&gt;
Once the binaries have been collected it will get the manifest files from the manifest folder, copying all the files starting with &lt;strong&gt;FolderStartsWith&lt;/strong&gt;. (&lt;em&gt;This is used as it will be the same in both cases&lt;/em&gt;)&lt;br&gt;&lt;br&gt;
Now you need to get the Click once shortcut (file) and place it in the restore location. The application will look at the user desktop for a file that start with the &lt;strong&gt;ShortCurtStartsWith&lt;/strong&gt;. This is needed as this is the key to make sure it uses the Click once logic. (&lt;em&gt;This short cut is not a normal short cut, its a “.appref-ms” file&lt;/em&gt;)&lt;br&gt;&lt;br&gt;
The final part of this is to make sure there is a short cut to itself and it will use the &lt;strong&gt;ShortCurtDisplay&lt;/strong&gt; value to set the display name.   &lt;/p&gt;

&lt;p&gt;Backup registration&lt;br&gt;&lt;br&gt;
The click once application will not work, making a binary backup and then restoring only. Click once requires user’s registration data as well.&lt;br&gt;&lt;br&gt;
You do need to get all the data from the below registration location, linked to your application.  &lt;/p&gt;

&lt;p&gt;Software\Classes\Software\Microsoft\Windows\CurrentVersion\Deployment\SideBySide\2.0  &lt;/p&gt;

&lt;p&gt;Invoke&lt;br&gt;&lt;br&gt;
The original shortcut for your application has now has been replace with a short cut to this application. So once invoked it find out if it needs to restore or just invoke the application as normal.  &lt;/p&gt;

&lt;p&gt;Restore&lt;br&gt;&lt;br&gt;
As the user now uses this application to invoke their application, due to the new short cut. It will check if the Current folder is within the Click once location. If not present it will restore the registration and physical folders.   &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Registration&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
This will restore the users registration keys and values required for your click once application to run again.&lt;br&gt;&lt;br&gt;
The restore application will use the data collected from the backup and restore the registration to match, what it was at the below registration location.&lt;br&gt;&lt;br&gt;
&lt;em&gt;Full example in the example application on my &lt;a href="%E2%80%9D"&gt;GitHub repo&lt;/a&gt;&lt;/em&gt;  &lt;/p&gt;

&lt;p&gt;\HKEY_CURRENT_USER\Software\Classes\Software\Microsoft\Windows\CurrentVersion\Deployment\SideBySide\2.0  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Binaries&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The backup folder and files are copied form the backup location to the below location.&lt;br&gt;&lt;br&gt;
&lt;em&gt;Full example in the example application on my &lt;a href="%E2%80%9D"&gt;GitHub repo&lt;/a&gt;&lt;/em&gt;  &lt;/p&gt;

&lt;p&gt;C:\Users\Chris.HEALTHDIAGNOSTI\AppData\Local\Apps\2.0 location&lt;/p&gt;


</description>
      <category>clickonce</category>
      <category>roamingprofiles</category>
      <category>restore</category>
      <category>windows10</category>
    </item>
  </channel>
</rss>
