<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>C#</title>
        <link>http://geekswithblogs.net/karskip/category/7335.aspx</link>
        <description>C#</description>
        <language>en-US</language>
        <copyright>Peter K</copyright>
        <managingEditor>buttweld1@gmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>ASP Web Setup Project Build Failing with No Errors</title>
            <link>http://geekswithblogs.net/karskip/archive/2009/04/23/131413.aspx</link>
            <description>I've been messing around with Web Setup Projects in Visual Studio 2008 and have been using them to deploy an ASP application I've been working on. One thing I've learned is that Web Setup is very temp&lt;span style="text-decoration: underline;"&gt;&lt;span style="font-style: italic;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;eramental as far as how your development environment is setup. I've had to do everything from computer restarts to registry hacks to get my Projects to build, and thought I had finally nailed down all the issues until I had to redeploy my application today.&lt;br /&gt;
&lt;br /&gt;
Upon building the Web Setup project I would get the "Build Failed" message along with no errors. Puzzled, I enabled detailed build logging in Visual Studio's options. And still, no errors. &lt;br /&gt;
&lt;br /&gt;
As developers we've all gone through the process of problem solving. You start trying reasonable solutions that seem logically correlated to the issue at hand, and failing that slowly devolve into more obscure and senseless solutions that aren't even remotely related to what you're trying to fix. And this is precisely what happened.&lt;br /&gt;
&lt;br /&gt;
What fixed my problem? Instead of opening my solution from the "Recent Projects" menu in the Visual Studio Start Page, I opened the solution through File &amp;gt; Open &amp;gt; Web Site...&lt;br /&gt;
&lt;br /&gt;
Like I said, a senseless solution to a problem that should have never existed in the first place.&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131413"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131413" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/karskip/aggbug/131413.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Peter K</dc:creator>
            <guid>http://geekswithblogs.net/karskip/archive/2009/04/23/131413.aspx</guid>
            <pubDate>Thu, 23 Apr 2009 09:24:55 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/karskip/comments/131413.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/karskip/archive/2009/04/23/131413.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/karskip/comments/commentRss/131413.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/karskip/services/trackbacks/131413.aspx</trackback:ping>
        </item>
        <item>
            <title>Converting System.Data.LINQ.Binary to an ASCII Encoded String</title>
            <link>http://geekswithblogs.net/karskip/archive/2009/04/22/131390.aspx</link>
            <description>I ran into a situation where I was storing files in a database as a binary field. Some of these files were in HTML format and I wanted to dynamically display them inside of some ASP pages I was developing. After a bit of research I was finding a lot of other solutions people were using involved timestamp conversions which were not ASCII based like HTML. The following code will convert your binary object into ASCII and display it as it was originally uploaded. &lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;byte&lt;/span&gt;[] myByteArray = myBinaryObj.ToArray();&lt;br /&gt;System.Text.ASCIIEncoding enc = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Text.ASCIIEncoding();&lt;br /&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; result = enc.GetString(myByteArray);&lt;/pre&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131390"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131390" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/karskip/aggbug/131390.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Peter K</dc:creator>
            <guid>http://geekswithblogs.net/karskip/archive/2009/04/22/131390.aspx</guid>
            <pubDate>Wed, 22 Apr 2009 08:09:09 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/karskip/comments/131390.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/karskip/archive/2009/04/22/131390.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/karskip/comments/commentRss/131390.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/karskip/services/trackbacks/131390.aspx</trackback:ping>
        </item>
        <item>
            <title>Dynamically Creating HTML Elements Using Javascript</title>
            <link>http://geekswithblogs.net/karskip/archive/2007/11/26/117137.aspx</link>
            <description>Suppose you want your users to submit a list of items through your web page. These items could be inputted through many means such as a text box, combobox, listbox, etc. There are many ghetto solutions you could use to implement this like comma delimited lists or multiple postbacks. There are however much more elegant, and suprisingly easier ways of doing this using javascript. As an example we will start with an input box with a link below it that allows you to spawn several more input boxes. In addition, each spawned input box comes with its own delete link, allowing the user to remove items if they choose to. Each input box is given a unique incremented ID that can be easily accessed later on through postback.&lt;br /&gt;
&lt;br /&gt;
Here's the javascript that makes it work:
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt; &lt;span class="attr"&gt;language&lt;/span&gt;&lt;span class="kwrd"&gt;="javascript"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;     &lt;br /&gt;    &lt;span class="kwrd"&gt;&lt;/span&gt;&lt;span class="kwrd"&gt;var&lt;/span&gt; software_number = 1;&lt;br /&gt;    &lt;span class="kwrd"&gt;function&lt;/span&gt; addSoftwareInput() &lt;br /&gt;    {&lt;br /&gt;        &lt;span class="kwrd"&gt;var&lt;/span&gt; d = document.createElement(&lt;span class="str"&gt;"div"&lt;/span&gt;);&lt;br /&gt;        &lt;span class="kwrd"&gt;var&lt;/span&gt; l = document.createElement(&lt;span class="str"&gt;"a"&lt;/span&gt;);&lt;br /&gt;        &lt;span class="kwrd"&gt;var&lt;/span&gt; software = document.createElement(&lt;span class="str"&gt;"input"&lt;/span&gt;);&lt;br /&gt;        software.setAttribute(&lt;span class="str"&gt;"type"&lt;/span&gt;, &lt;span class="str"&gt;"text"&lt;/span&gt;);&lt;br /&gt;        software.setAttribute(&lt;span class="str"&gt;"id"&lt;/span&gt;, &lt;span class="str"&gt;"software"&lt;/span&gt;+software_number);&lt;br /&gt;        software.setAttribute(&lt;span class="str"&gt;"name"&lt;/span&gt;, &lt;span class="str"&gt;"software"&lt;/span&gt;+software_number);&lt;br /&gt;        software.setAttribute(&lt;span class="str"&gt;"size"&lt;/span&gt;, &lt;span class="str"&gt;"50"&lt;/span&gt;);&lt;br /&gt;        software.setAttribute(&lt;span class="str"&gt;"maxlength"&lt;/span&gt;, &lt;span class="str"&gt;"74"&lt;/span&gt;);&lt;br /&gt;        l.setAttribute(&lt;span class="str"&gt;"href"&lt;/span&gt;, &lt;span class="str"&gt;"javascript:removeSoftwareInput('s"&lt;/span&gt;+software_number+&lt;span class="str"&gt;"');"&lt;/span&gt;);&lt;br /&gt;        d.setAttribute(&lt;span class="str"&gt;"id"&lt;/span&gt;, &lt;span class="str"&gt;"s"&lt;/span&gt;+software_number); &lt;br /&gt;        &lt;br /&gt;        &lt;span class="kwrd"&gt;var&lt;/span&gt; image = document.createTextNode(&lt;span class="str"&gt;"Delete"&lt;/span&gt;);&lt;br /&gt;        l.appendChild(image);&lt;br /&gt;        &lt;br /&gt;        &lt;br /&gt;        d.appendChild(software);&lt;br /&gt;        d.appendChild(l);&lt;br /&gt;        &lt;br /&gt;        document.getElementById(&lt;span class="str"&gt;"moreSoftware"&lt;/span&gt;).appendChild(d);&lt;br /&gt;        software_number++;&lt;br /&gt;        software.focus();&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    &lt;span class="kwrd"&gt;function&lt;/span&gt; removeSoftwareInput(i) &lt;br /&gt;    { &lt;br /&gt;        &lt;span class="kwrd"&gt;var&lt;/span&gt; elm = document.getElementById(i); &lt;br /&gt;        document.getElementById(&lt;span class="str"&gt;"moreSoftware"&lt;/span&gt;).removeChild(elm); &lt;br /&gt;    }&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
And the tiny amount of html to get it to show up:
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text"&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="software0"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="software0"&lt;/span&gt; &lt;span class="attr"&gt;size&lt;/span&gt;&lt;span class="kwrd"&gt;="50"&lt;/span&gt; &lt;span class="attr"&gt;maxlength&lt;/span&gt;&lt;span class="kwrd"&gt;="74"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;                &lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="moreSoftware"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="moreSoftwareLink"&lt;/span&gt; &lt;span class="attr"&gt;style&lt;/span&gt;&lt;span class="kwrd"&gt;="display:block;"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt; &lt;span class="attr"&gt;href&lt;/span&gt;&lt;span class="kwrd"&gt;="javascript:addSoftwareInput();"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Add Another Item&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
You can paste the above HTML and javascript into your own webpage to see it in action. &lt;br /&gt;
&lt;br /&gt;
In some languages such as PHP, accessing these dynamically created elements after postback isn't an issue, it's a simple matter of using a for loop to iterate through each element. However this becomes a challenge if you're using ASP.NET. The problem is that these new elements are created on the client side, and once submitted, the server no longer sees them. The workaround is to use javascript to collect the contents of each element and stuff them into a hidden element in a delimited format. In the case of ASP.NET this hidden element would have to be declared within the page that is originally sent to the client. Then on postback we can collect the contents of this single element, break up each list item by the delimiter and deal with them as we normally would.  First we create our hidden attribute to dump our item contents on submit:
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="ninjainput"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="hidden"&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="ninjainput"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
We'll call it "ninjainput", because it's stealthy and mysterious, like a ninja. Next, we'll insert an additional javascript function that will populate our ninjainput when the user submits the page.
&lt;pre class="csharpcode"&gt;function populateStaticInput()&lt;br /&gt;{&lt;br /&gt;    var n = document.getElementById("ninjainput");&lt;br /&gt;    var allsoftware = "";&lt;br /&gt;    for( var i = 0; i &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt; software_number; i++)&lt;br /&gt;    {&lt;br /&gt;        var currentele = document.getElementById("software"+i);&lt;br /&gt;        if(currentele != null)&lt;br /&gt;        {&lt;br /&gt;            if(currentele.value.length &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; 0)&lt;br /&gt;            {&lt;br /&gt;                if(currentele.value.length &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; 74)&lt;br /&gt;                    currentele.value = currentele.value.substring(0, 74);&lt;br /&gt;                allsoftware = allsoftware + "~&lt;span class="kwrd"&gt;&amp;lt;&amp;gt;&lt;/span&gt;~" + currentele.value;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    n.value = allsoftware;     &lt;br /&gt;}&lt;/pre&gt;
Notice that we are delimiting each item with a "~&amp;lt;&amp;gt;~". Make sure to add this attribute to your form tag: onsubmit="javascript:populateStaticInput();" This way the javascript will run and populate our ninjainput control before the page is sent to the server. Lastly, we will need a function (the example below is in C#) that will cut up the submitted list of items into a usable format, in this case an array of strings.
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;[] GetAllSoftwareInList(&lt;span class="kwrd"&gt;string&lt;/span&gt; rawsoftlist)&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;string&lt;/span&gt;[] asoft = rawsoftlist.Split(&lt;span class="str"&gt;"~&amp;lt;&amp;gt;~"&lt;/span&gt;.ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);&lt;br /&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; asoft;&lt;br /&gt;}&lt;/pre&gt;
And there you have it, the user doesn't have to endure multiple postbacks or keep track of a comma delimited list. It's presented in an organized and intuitive manner to the user and not too painful to implement for the developer.&lt;br /&gt;
&lt;div class="techtags"&gt;Tech Tags: &lt;a href="http://technorati.com/tag/javascript" rel="tag" class="techtag"&gt;javascript&lt;/a&gt; &lt;a href="http://technorati.com/tag/ASP.NET" rel="tag" class="techtag"&gt;ASP.NET&lt;/a&gt; &lt;a href="http://technorati.com/tag/dynamic+HTML" rel="tag" class="techtag"&gt;dynamic+HTML&lt;/a&gt; &lt;/div&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=117137"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=117137" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/karskip/aggbug/117137.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Peter K</dc:creator>
            <guid>http://geekswithblogs.net/karskip/archive/2007/11/26/117137.aspx</guid>
            <pubDate>Mon, 26 Nov 2007 09:59:01 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/karskip/comments/117137.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/karskip/archive/2007/11/26/117137.aspx#feedback</comments>
            <slash:comments>4</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/karskip/comments/commentRss/117137.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/karskip/services/trackbacks/117137.aspx</trackback:ping>
        </item>
    </channel>
</rss>