<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Marcus Nyberg &#187; Programmering</title>
	<atom:link href="http://www.marcusnyberg.com/category/programmering/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.marcusnyberg.com</link>
	<description>Digital and dangerous</description>
	<lastBuildDate>Fri, 03 Feb 2012 08:41:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to install a shared network printer with VB.NET and WMI</title>
		<link>http://www.marcusnyberg.com/2010/11/17/how-to-install-a-network-printer-with-vb-net-and-wmi/</link>
		<comments>http://www.marcusnyberg.com/2010/11/17/how-to-install-a-network-printer-with-vb-net-and-wmi/#comments</comments>
		<pubDate>Wed, 17 Nov 2010 14:39:56 +0000</pubDate>
		<dc:creator>marcus</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programmering]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://www.marcusnyberg.com/?p=848</guid>
		<description><![CDATA[Today I show you an example of how to install a network printer with VB.NET and WMI by using the AddPrinterConnection method of the wmi Win32_Printer class. Just replace hostname with the name of the printserver/workstation and queuename with the shared printer queuename. Try Dim scope As ManagementScope = New ManagementScope("root\CIMV2") scope.Options.Impersonation = ImpersonationLevel.Impersonate scope.Connect() [...]]]></description>
			<content:encoded><![CDATA[<p>Today I show you an example of how to install a network printer with VB.NET and WMI by using the <a href="http://msdn.microsoft.com/en-us/library/aa384769(VS.85).aspx">AddPrinterConnection</a> method of the wmi <a href="http://msdn.microsoft.com/en-us/library/aa394363(v=VS.85).aspx">Win32_Printer</a> class. Just replace hostname with the name of the printserver/workstation and queuename with the shared printer queuename.</p>
<pre name="code" class="vb.net">
        Try

            Dim scope As ManagementScope = New ManagementScope("root\CIMV2")
            scope.Options.Impersonation = ImpersonationLevel.Impersonate
            scope.Connect()

            Dim path As New ManagementPath("Win32_Printer")
            Dim mgtClass As New ManagementClass(scope, path, Nothing)

            Dim inputParameters As ManagementBaseObject = mgtClass.GetMethodParameters("AddPrinterConnection")
            inputParameters("Name") = "\\hostname\queuename"

            Dim outputParameters As ManagementBaseObject = mgtClass.InvokeMethod("AddPrinterConnection", inputParameters, Nothing)
            Dim returnValue As UInteger = UInteger.Parse(outputParameters("ReturnValue"))

            If (returnValue = 0) Then
                Console.WriteLine("Success")
            ElseIf (returnValue = 5) Then
                Console.WriteLine("Access Denied")
            ElseIf (returnValue = 1801) Then
                Console.WriteLine("Invalid Printer Name")
            ElseIf (returnValue = 1930) Then
                Console.WriteLine("Incompatible Printer Driver")
            End If

        Catch ex As Exception

        End Try
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusnyberg.com/2010/11/17/how-to-install-a-network-printer-with-vb-net-and-wmi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running and debugging a SQL Server 2000 DTS Package in Visual Basic 6.0</title>
		<link>http://www.marcusnyberg.com/2010/08/12/running-and-debugging-a-sql-server-2000-dts-package-in-visual-basic-6-0/</link>
		<comments>http://www.marcusnyberg.com/2010/08/12/running-and-debugging-a-sql-server-2000-dts-package-in-visual-basic-6-0/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 12:28:55 +0000</pubDate>
		<dc:creator>marcus</dc:creator>
				<category><![CDATA[Programmering]]></category>
		<category><![CDATA[SQL-server]]></category>

		<guid isPermaLink="false">http://www.marcusnyberg.com/?p=696</guid>
		<description><![CDATA[If you have a fairly complex DTS-package (Data Transformation Services) in SQL-Server 2000 and don&#8217;t have a clue of what it does and have a limited understanding of dts read this. You can &#8221;export&#8221; the package to VB6 and by doing so you can read the code and run and debug the script from the [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a fairly complex DTS-package (<a href="http://en.wikipedia.org/wiki/Data_Transformation_Services">Data Transformation Services</a>) in SQL-Server 2000 and don&#8217;t have a clue of what it does and have a limited understanding of dts read this. You can &#8221;export&#8221; the package to VB6 and by doing so you can read the code and run and debug the script from the VB6-IDE. You can even run it in <a href="http://www.sqldts.com/264.aspx">VB.NET</a>. This is quite old school but sometimes necessary to do in legacy systems if you want to edit a complex dts-script.</p>
<p><strong>Step 1 &#8211; Export the dts-package to visual basic</strong></p>
<p>Open your DTS-package in SQL-server 2000.<br />
<a href="http://www.marcusnyberg.com/wp-content/uploads/2010/08/dts-package.jpg"><img src="http://www.marcusnyberg.com/wp-content/uploads/2010/08/dts-package-253x300.jpg" alt="" title="dts-package" width="253" height="300" class="alignnone size-medium wp-image-697" /></a></p>
<p>Choose &#8221;Package -> Save as&#8221; in the menu and then change &#8221;Location&#8221; to &#8221;Visual Basic file&#8221; in the dialog. Press OK and then a bas-file (VB-module) is saved to disk.</p>
<p><a href="http://www.marcusnyberg.com/wp-content/uploads/2010/08/dts-visual-basic.jpg"><img src="http://www.marcusnyberg.com/wp-content/uploads/2010/08/dts-visual-basic-300x258.jpg" alt="" title="dts-visual-basic" width="300" height="258" class="alignnone size-medium wp-image-698" /></a></p>
<p><strong>Step 2 &#8211; Create a visual basic project</strong></p>
<p>Open Microsoft Visual Basic IDE. Choose to create a new &#8221;Standard EXE&#8221; project then click &#8221;Open&#8221;.  Remove the default Forms1 from the project. Then you add the dts bas-file to the project with &#8221;Project -> Add module&#8221;. The result should should look like below.</p>
<p><a href="http://www.marcusnyberg.com/wp-content/uploads/2010/08/dts-vb6-3.jpg"><img src="http://www.marcusnyberg.com/wp-content/uploads/2010/08/dts-vb6-3-300x216.jpg" alt="" title="dts-vb6-3" width="300" height="216" class="alignnone size-medium wp-image-706" /></a></p>
<p><strong>Step 2 &#8211; Executing and debugging the dts-package</strong></p>
<p>Go to &#8221;Project -> References&#8221; and add references to &#8221;Microsoft DTSPackage Object Library&#8221; and &#8221;Microsoft DTS Custom Task Object Library&#8221;. Now you are ready to edit your package.</p>
<p><a href="http://www.marcusnyberg.com/wp-content/uploads/2010/08/dts-vb6-references.jpg"><img src="http://www.marcusnyberg.com/wp-content/uploads/2010/08/dts-vb6-references-300x237.jpg" alt="" title="dts-vb6-references" width="300" height="237" class="alignnone size-medium wp-image-708" /></a></p>
<p>To debug the package you simply set a breakpoint and hit F5.</p>
<p><a href="http://www.marcusnyberg.com/wp-content/uploads/2010/08/dts-debugging.jpg"><img src="http://www.marcusnyberg.com/wp-content/uploads/2010/08/dts-debugging-300x173.jpg" alt="" title="dts-debugging" width="300" height="173" class="alignnone size-medium wp-image-710" /></a></p>
<p>Now feel free to fool around with the package/module and make the changes that you need. It is not easy at first but after a while you get the hang of it.</p>
<p><strong>Step 3 -Saving the dts-package to SQL-server</strong></p>
<p>When your package is ready for deployment you can deploy it through VB. Instead of executing the package you can easily save it to your SQL-server.</p>
<p>Search for the &#8221;Save or execute package&#8221; section in the module. Comment the Execute statement and uncomment the SaveToSQLServer row.</p>
<p><a href="http://www.marcusnyberg.com/wp-content/uploads/2010/08/dts-save-package.jpg"><img src="http://www.marcusnyberg.com/wp-content/uploads/2010/08/dts-save-package-300x92.jpg" alt="" title="dts-save-package" width="300" height="92" class="alignnone size-medium wp-image-712" /></a></p>
<p>Hit F5 to run the module. If everything works fine your new dts-package shows up in SQL-server.</p>
<p>More help with DTS can be found and at <a href="http://www.sqldts.com/">sqldts.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusnyberg.com/2010/08/12/running-and-debugging-a-sql-server-2000-dts-package-in-visual-basic-6-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create a printerqueu with .NET and WMI</title>
		<link>http://www.marcusnyberg.com/2010/01/12/how-to-create-a-printerqueu-with-net-and-wmi/</link>
		<comments>http://www.marcusnyberg.com/2010/01/12/how-to-create-a-printerqueu-with-net-and-wmi/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 11:33:22 +0000</pubDate>
		<dc:creator>marcus</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programmering]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.marcusnyberg.com/?p=392</guid>
		<description><![CDATA[This is an example of how you create a printerqueue with .NET and WMI (Windows Management Instrumentation). A list of properties can be found at MSDN Win32_Printer Other topics: How to install printerdrivers with wmi and VB.NET How to create TCP/IP printerports with .NET Imports System.Management Dim shared as Boolean = true Try Dim mp [...]]]></description>
			<content:encoded><![CDATA[<p>This is an example of how you create a printerqueue with .NET and WMI (Windows Management Instrumentation).  </p>
<p>A list of properties can be found at <a href="http://msdn.microsoft.com/en-us/library/aa394363%28VS.85%29.aspx">MSDN Win32_Printer</a></p>
<p>Other topics:<br />
<a href="http://www.marcusnyberg.com/2009/11/23/install-printerdrivers-wmi/">How to install printerdrivers with wmi and VB.NET</a><br />
<a href="http://www.marcusnyberg.com/2009/12/11/install-printerports-with-wmi-and-vb-net/">How to create TCP/IP printerports with .NET</a></p>
<pre name="code" class="vb.net">
Imports System.Management

Dim shared as Boolean = true

Try
 Dim mp As ManagementPath = New ManagementPath("Win32_Printer")
 Dim co As ConnectionOptions = New ConnectionOptions()
 co.EnablePrivileges = True
 co.Impersonation = ImpersonationLevel.Impersonate

 Dim ms As ManagementScope = New ManagementScope("\\" + Environment.MachineName + "\root\cimv2", co)

 Dim printerObject As ManagementObject = New ManagementClass(ms, mp, Nothing).CreateInstance()
 printerObject("PortName") = "IP_192.168.0.2"
 printerObject("DriverName") = "DriverName"
 printerObject("DeviceID") = "queuename"
 printerObject("Location") = "Placement of printer"
 printerObject("Comment") = "Some comments"

 If (shared) Then
  printerObject("Shared") = True
  printerObject("ShareName") = "Sharename"
  'printerObject("Published") = False ' Publish printer
 End If

 Dim options As PutOptions = New PutOptions()
 options.Type = PutType.UpdateOrCreate
 printerObject.Put(options)

Catch ex As Exception
 ' Do something
End Try
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusnyberg.com/2010/01/12/how-to-create-a-printerqueu-with-net-and-wmi/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Install printerports with WMI and VB.NET</title>
		<link>http://www.marcusnyberg.com/2009/12/11/install-printerports-with-wmi-and-vb-net/</link>
		<comments>http://www.marcusnyberg.com/2009/12/11/install-printerports-with-wmi-and-vb-net/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 14:06:17 +0000</pubDate>
		<dc:creator>marcus</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programmering]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://www.marcusnyberg.com/?p=347</guid>
		<description><![CDATA[This is an example of how you install TCP/IP printerports with .NET and WMI (Windows Management Instrumentation). A list of properties can be found at MSDN Win32_TCPIPPrinterPort Other topics: How to install printerdrivers with wmi and VB.NET How to create a printerqueu with .NET and WMI Imports System.Management Try Dim mp As ManagementPath = New [...]]]></description>
			<content:encoded><![CDATA[<p>This is an example of how you install TCP/IP printerports with .NET and WMI (Windows Management Instrumentation).  </p>
<p>A list of properties can be found at <a href="http://msdn.microsoft.com/en-us/library/aa394492%28VS.85%29.aspx">MSDN Win32_TCPIPPrinterPort</a></p>
<p>Other topics:<br />
<a href="http://www.marcusnyberg.com/2009/11/23/install-printerdrivers-wmi/">How to install printerdrivers with wmi and VB.NET</a><br />
<a href="http://www.marcusnyberg.com/2010/01/12/how-to-create-a-printerqueu-with-net-and-wmi/">How to create a printerqueu with .NET and WMI</a></p>
<pre name="code" class="vb.net">
Imports System.Management

Try
  Dim mp As ManagementPath = New ManagementPath("Win32_TCPIPPrinterPort")
  Dim co As ConnectionOptions = New ConnectionOptions()
  co.EnablePrivileges = True

  Dim ms As ManagementScope = New ManagementScope("\\" + Environment.MachineName + "\root\cimv2", co)

  Dim port As ManagementObject = New ManagementClass(ms, mp, Nothing).CreateInstance()
  port.SetPropertyValue("Name", "portname")
  port.SetPropertyValue("Protocol", 1)
  port.SetPropertyValue("HostAddress", "10.15.12.12")
  port.SetPropertyValue("PortNumber", "9100")

  Dim po As PutOptions = New PutOptions()
  po.UseAmendedQualifiers = True
  po.Type = PutType.UpdateOrCreate
  port.Put(po)
Catch ex As Exception
  ' do something
End Try
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusnyberg.com/2009/12/11/install-printerports-with-wmi-and-vb-net/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Install printerdrivers with WMI and VB.NET</title>
		<link>http://www.marcusnyberg.com/2009/11/23/install-printerdrivers-wmi/</link>
		<comments>http://www.marcusnyberg.com/2009/11/23/install-printerdrivers-wmi/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 08:26:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programmering]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://www.marcusnyberg.com/?p=310</guid>
		<description><![CDATA[This is an example of how you install printerdrivers with .NET and WMI (Windows Management Instrumentation). Most examples on the Internet shows how this can be done with vbscript, printui.dll and such&#8230; A list of properties can be found at MSDN Win32_PrinterDriver Other topics: How to install printerports with WMI and VB.NET How to create [...]]]></description>
			<content:encoded><![CDATA[<p>This is an example of how you install printerdrivers with .NET and WMI (Windows Management Instrumentation). Most examples on the Internet shows how this can be done with vbscript, printui.dll and such&#8230;</p>
<p>A list of properties can be found at <a href="http://msdn.microsoft.com/en-us/library/aa394366(VS.85).aspx">MSDN Win32_PrinterDriver</a></p>
<p>Other topics:<br />
<a href="http://www.marcusnyberg.com/2009/12/11/install-printerports-with-wmi-and-vb-net/">How to install printerports with WMI and VB.NET</a><br />
<a href="http://www.marcusnyberg.com/2010/01/12/how-to-create-a-printerqueu-with-net-and-wmi/">How to create a printerqueu with .NET and WMI</a></p>
<pre name="code" class="vb.net">
Imports System.Management

Dim infPath  as String = "c:\driver\printerdriver.inf"
Dim mp As ManagementPath = New ManagementPath("Win32_PrinterDriver")

Dim co As ConnectionOptions = New ConnectionOptions()
co.EnablePrivileges = True

Dim ms As ManagementScope = New ManagementScope("\\" + Environment.MachineName + "\root\cimv2", co)

Dim mcPrinterDriver As New ManagementClass(ms, mp, Nothing)
mcPrinterDriver.SetPropertyValue("Name", "drivername")
mcPrinterDriver.SetPropertyValue("SupportedPlatform", "Windows NT x86") ' x86-architecture
'mcPrinterDriver.SetPropertyValue("SupportedPlatform", "Windows x64") ' x64-architecture
mcPrinterDriver.SetPropertyValue("Version", 3)
mcPrinterDriver.SetPropertyValue("FilePath", System.IO.Path.GetDirectoryName(infPath))
mcPrinterDriver.SetPropertyValue("InfName", infPath)

Dim inParams As System.Management.ManagementBaseObject = Nothing
inParams = mcPrinterDriver.GetMethodParameters("AddPrinterDriver")
inParams("DriverInfo") = CType(mcPrinterDriver, System.Management.ManagementBaseObject)
Dim outParams As System.Management.ManagementBaseObject = mcPrinterDriver.InvokeMethod("AddPrinterDriver", inParams, Nothing)

Dim uiReturnValue As UInteger = System.Convert.ToUInt32(outParams.Properties("ReturnValue").Value)
</pre>
<p>I have tested this in Windows XP, Windows 7 and Windows 2008R2. Make sure your account has privileges to install drivers.</p>
<p>On Windows XP the drivers are installed physically to:<br />
C:\WINNT\system32\spool\drivers</p>
<p>And in the registry:<br />
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusnyberg.com/2009/11/23/install-printerdrivers-wmi/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Sun Certifierad Java Programmerare (SCJP)</title>
		<link>http://www.marcusnyberg.com/2009/03/23/sun-certifierad-java-programmerare-scjp/</link>
		<comments>http://www.marcusnyberg.com/2009/03/23/sun-certifierad-java-programmerare-scjp/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 15:46:44 +0000</pubDate>
		<dc:creator>marcus</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[Programmering]]></category>

		<guid isPermaLink="false">http://www.marcusnyberg.com/?p=196</guid>
		<description><![CDATA[Det har inte blivit något skrivet här på sistone eftersom jag pluggat frenetiskt de senaste veckor för att certifiera mig inom programmeringsspråket Java. Idag skrev jag provet hos Cornerstone i Sundsvall och klarade det. Jag fick 68% rätt på de 72 frågorna, där gränsen var 59%. Yippie, fy fan vad jag fick slita&#8230; Nu är [...]]]></description>
			<content:encoded><![CDATA[<p>Det har inte blivit något skrivet här på sistone eftersom jag pluggat frenetiskt de senaste veckor för att certifiera mig inom programmeringsspråket Java. Idag skrev jag provet hos Cornerstone i Sundsvall och klarade det. Jag fick 68% rätt på de 72 frågorna, där gränsen var 59%. Yippie, fy fan vad jag fick slita&#8230;</p>
<p>Nu är jag alltså <a href="http://www.sun.com/training/certification/java/scjp.xml" target="_blank">certifierad java utvecklare</a> enligt Sun. Nästa mål är att certifiera mig som <a href="http://www.microsoft.com/learning/mcp/mcts/" target="_blank">Microsoft Certified Technology Specialist (MCTS)</a> i .NET Framework 2.0.</p>
<p>Detta ska firas i helgen!</p>
<p><img src="http://www.marcusnyberg.com/wp-content/uploads/2009/03/champagnebottle.jpg" alt="champagnebottle" title="champagnebottle" width="281" height="400" class="alignnone size-full wp-image-198" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusnyberg.com/2009/03/23/sun-certifierad-java-programmerare-scjp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Confirm javascript on .NET Linkbutton in datagrids</title>
		<link>http://www.marcusnyberg.com/2008/05/21/confirm-javascript-on-net-linkbutton-in-datagrids/</link>
		<comments>http://www.marcusnyberg.com/2008/05/21/confirm-javascript-on-net-linkbutton-in-datagrids/#comments</comments>
		<pubDate>Wed, 21 May 2008 12:37:03 +0000</pubDate>
		<dc:creator>marcus</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Programmering]]></category>

		<guid isPermaLink="false">http://www.marcusnyberg.com/2008/05/21/confirm-javascript-on-net-linkbutton-in-datagrids/</guid>
		<description><![CDATA[Today I was struck with some really weird behaviour from a LinkButton in a Datagrid. I could not get the the confirm() javascript to fire. My code-behind was something like this: LinkButton lb = ((LinkButton)dgItem.FindControl(&#8221;lb&#8221;)); lb.Attributes["onClick"] = &#8221;return confirm(&#8216;Do you really want to do that?&#8217;);&#8221;; I dont really know why the onClick confirm-box does not [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was struck with some really weird behaviour from a LinkButton in a Datagrid. I could not get the the confirm() javascript to fire. My code-behind was something like this:</p>
<p class="kod">
LinkButton lb = ((LinkButton)dgItem.FindControl(&#8221;lb&#8221;));<br />
lb.Attributes["onClick"] = &#8221;return confirm(&#8216;Do you really want to do that?&#8217;);&#8221;;
</p>
<p>I dont really know why the onClick confirm-box does not fire before the href PostBack. However, the solution was to put the LinkButton inside a span and put the onClick attribute on the span.</p>
<p class="kod">
// Web page<br />
&lt;span runat=&quot;server&quot; id=&quot;spanLb&quot;&gt;<br />
&lt;Linkbutton stuff/&gt;<br />
&lt;/span&gt;
</p>
<p class="kod">
//Code-behind<br />
HtmlControl spanLb = ((HtmlControl)dgItem.FindControl(&#8221;spanLb&#8221;));<br />
spanLb.Attributes["onClick"] = &#8221;return confirm(&#8216;Do you really want to do that?&#8217;);&#8221;;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusnyberg.com/2008/05/21/confirm-javascript-on-net-linkbutton-in-datagrids/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Strip tags from a string</title>
		<link>http://www.marcusnyberg.com/2008/05/21/strip-tags-from-a-string/</link>
		<comments>http://www.marcusnyberg.com/2008/05/21/strip-tags-from-a-string/#comments</comments>
		<pubDate>Wed, 21 May 2008 12:14:24 +0000</pubDate>
		<dc:creator>marcus</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Programmering]]></category>

		<guid isPermaLink="false">http://www.marcusnyberg.com/2008/05/21/strip-tags-from-a-string/</guid>
		<description><![CDATA[It is often useful to have a way to strip html or other tags from a string. Php has the strip_tags function. Stripping tags could be done in .NET with the following code that returns the stripped string: public static string StripTags(string str) { return Regex.Replace(str, @&#8221;&#8221;, string.Empty); }]]></description>
			<content:encoded><![CDATA[<p>It is often useful to have a way to strip html or other tags from a string. Php has the <a href="http://se.php.net/manual/en/function.strip-tags.php">strip_tags</a> function. Stripping tags could be done in .NET with the following code that returns the stripped string:</p>
<p class="kod">
	public static string StripTags(string str)<br />
	{<br />
		return Regex.Replace(str, @&#8221;<(.|\n)*?>&#8221;, string.Empty);<br />
	}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusnyberg.com/2008/05/21/strip-tags-from-a-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>firstChild and nextSibling differences between Firefox and Explorer</title>
		<link>http://www.marcusnyberg.com/2008/02/28/firstchild-and-nextsibling-differences-between-firefox-and-explorer/</link>
		<comments>http://www.marcusnyberg.com/2008/02/28/firstchild-and-nextsibling-differences-between-firefox-and-explorer/#comments</comments>
		<pubDate>Thu, 28 Feb 2008 12:20:11 +0000</pubDate>
		<dc:creator>marcus</dc:creator>
				<category><![CDATA[Programmering]]></category>

		<guid isPermaLink="false">http://www.marcusnyberg.com/2008/02/28/firstchild-and-nextsibling-differences-between-firefox-and-explorer/</guid>
		<description><![CDATA[This post describes a weird difference in how Internet Explorer and Firefox handles the Document Object Model (DOM). In my case I got different browser-behaviour when using firstChild and nextSibling in a javascript. The problem is that the Firefox DOM does not ignore line breaks and whitespaces while IE does. Instead of using firstChild and [...]]]></description>
			<content:encoded><![CDATA[<p>This <a href="http://www.agavegroup.com/?p=32">post</a> describes a weird difference in how Internet Explorer and Firefox handles the Document Object Model (DOM). In my case I got different browser-behaviour when using firstChild and nextSibling in a javascript. The problem is that the Firefox DOM does not ignore line breaks and whitespaces while IE does.</p>
<p>Instead of using firstChild and nextSibling you can use these functions (look below) that searches for the correct element in both major browsers.</p>
<p>Use getNextSibling(element) instead of element.nextSibling.<br />
Use getFirstChild(element) instead of element.firstChild.</p>
<p class="kod">
function getNextSibling(startBrother)<br />
{<br />
  endBrother=startBrother.nextSibling;<br />
  while(endBrother.nodeType!=1)<br />
  {<br />
    endBrother = endBrother.nextSibling;<br />
  }<br />
  return endBrother;<br />
}
</p>
<p class="kod">
function getFirstChild(elm)<br />
{<br />
  if ( !elm.childNodes.length )<br />
  {<br />
    return;<br />
  }<br />
  var children = elm.childNodes.length;<br />
  for ( var i = 0; i <= children; ++i )<br />
  {<br />
    if ( elm.childNodes[i].nodeType == 1 )<br />
    {<br />
      return elm.childNodes[i];<br />
    }<br />
  }<br />
  return;<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusnyberg.com/2008/02/28/firstchild-and-nextsibling-differences-between-firefox-and-explorer/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Submitta asp.NET formulär med enter-knappen</title>
		<link>http://www.marcusnyberg.com/2007/12/13/submitta-aspnet-formular-med-enter-knappen/</link>
		<comments>http://www.marcusnyberg.com/2007/12/13/submitta-aspnet-formular-med-enter-knappen/#comments</comments>
		<pubDate>Thu, 13 Dec 2007 15:10:31 +0000</pubDate>
		<dc:creator>marcus</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programmering]]></category>

		<guid isPermaLink="false">http://www.marcusnyberg.com/2007/12/13/submitta-aspnet-formular-med-enter-knappen/</guid>
		<description><![CDATA[En klassisk bugg i asp.NET (1.1 åtminstone) är att formulär med endast en textruta och en submit-knapp inte submittas då man fyller i rutan och trycker på enter-tangenten. Eller jo, sidan submittas men eventet för submit-knappen körs inte. Lösningen är enkel, men väldigt svår då man inte vet om att det är en bugg. Det [...]]]></description>
			<content:encoded><![CDATA[<p>En klassisk bugg i asp.NET (1.1 åtminstone) är att formulär med endast en textruta och en submit-knapp inte submittas då man fyller i rutan och trycker på enter-tangenten. Eller jo, sidan submittas men eventet för submit-knappen körs inte. Lösningen är enkel, men väldigt svår då man inte vet om att det är en bugg. Det räcker med att man skapar en osynlig textruta (input). En mer utförlig förklaring till fenomenet finns <a href="http://aspnet.4guysfromrolla.com/articles/060805-1.aspx" target="_blank">här</a>.</p>
<p>Exempel:</p>
<p class="kod"> &lt;input type=&#8221;text&#8221; style=&#8221;display:none&#8221;/&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusnyberg.com/2007/12/13/submitta-aspnet-formular-med-enter-knappen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

