<?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>Wacdesigns &#187; C#</title>
	<atom:link href="http://www.wacdesigns.com/category/net/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wacdesigns.com</link>
	<description>What about Creativity ?</description>
	<lastBuildDate>Fri, 02 Dec 2011 11:50:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Merge pdf files using C#</title>
		<link>http://www.wacdesigns.com/2008/10/03/merge-pdf-files-using-c/</link>
		<comments>http://www.wacdesigns.com/2008/10/03/merge-pdf-files-using-c/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 23:00:57 +0000</pubDate>
		<dc:creator>jf</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.wacdesigns.com/2008/10/03/merge-pdf-files-using-c/</guid>
		<description><![CDATA[Recently I had to create an assembly component using C# to merge multiple PDF files into one file. The specification was pretty straight forward: 1) Merge two of more PDF document into a single output PDF File. 2) Used on an ASP.NET Page After a few minutes of GOOG, I came up to this &#8220;ITextSharp&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I had to create an assembly component using C# to merge multiple PDF files into one file. The specification was pretty straight forward:<br />
1) Merge two of more PDF document into a single output PDF File.<br />
2) Used on an ASP.NET Page</p>
<p>After a few minutes of GOOG, I came up to this &#8220;<a title="ITextSharp" href="http://sourceforge.net/projects/itextsharp/" target="_blank">ITextSharp</a>&#8221;</p>
<blockquote><p>iText# (iTextSharp) is a port of the iText open source java library written entirely in C# for the .NET platform. iText# is a library that allows you to generate PDF files on the fly. It is implemented as an assembly.</p></blockquote>
<p><em>It must be noted that the assembly is coded and compiled using the .NET Framework 1.1. You might want to migrate to the version 2.0 or 3.5 of the .NET Framework. </em></p>
<p>With a some more research on PDF merging. I was able to create a class that will make use of the ITextSharp assembly and perform as the merge pdf operation as needed.</p>
<p>Here is the code:</p>
<pre>using iTextSharp.text;
using iTextSharp.text.pdf;

public class MergeEx
{
#region Fields
private string sourcefolder;
private string destinationfile;
private IList fileList = new ArrayList();
#endregion

#region Public Methods
///
/// Add a new file, together with a given docname to the fileList and namelist collection
///
public void AddFile(string pathnname)
{
fileList.Add(pathnname);
}

///
/// Generate the merged PDF
///
public void Execute()
{
MergeDocs();
}
#endregion

#region Private Methods
///
/// Merges the Docs and renders the destinationFile
///
private void MergeDocs()
{

//Step 1: Create a Docuement-Object
Document document = new Document();
try
{
//Step 2: we create a writer that listens to the document
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(destinationfile, FileMode.Create));

//Step 3: Open the document
document.Open();

PdfContentByte cb = writer.DirectContent;
PdfImportedPage page;

int n = 0;
int rotation = 0;

//Loops for each file that has been listed
foreach (string filename in fileList)
{
//The current file path
string filePath = sourcefolder + filename;

// we create a reader for the document
PdfReader reader = new PdfReader(filePath);

//Gets the number of pages to process
n = reader.NumberOfPages;

int i = 0;
while (i &lt; n)
{
i++;
document.SetPageSize(reader.GetPageSizeWithRotation(1));
document.NewPage();

//Insert to Destination on the first page
if (i == 1)
{
Chunk fileRef = new Chunk(" ");
fileRef.SetLocalDestination(filename);
document.Add(fileRef);
}

page = writer.GetImportedPage(reader, i);
rotation = reader.GetPageRotation(i);
if (rotation == 90 || rotation == 270)
{
cb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(i).Height);
}
else
{
cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
}
}
}
}
catch (Exception e) { throw e; }
finally { document.Close(); }
}
#endregion

#region Properties
///
/// Gets or Sets the SourceFolder
///
public string SourceFolder
{
get { return sourcefolder; }
set {sourcefolder = value; }
}

///
/// Gets or Sets the DestinationFile
///
public string DestinationFile
{
get { return destinationfile; }
set { destinationfile = value; }
}
#endregion
}
</pre>
<p>To use the MergeEx class:<br />
1) Initialize the class<br />
2) Set the SourceFolder and DestinationFile properties<br />
3) Using the AddFile method, add the source file names that need to be merged (Filename only since the SourceFolder has already been set)<br />
4) Call the Execute Method</p>
<p>If everything works fine you will find your Merged PDF Document at your stated destination file.</p>
<p>The code is pretty much self decribed. If there is any question, i can always be contacted via this post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wacdesigns.com/2008/10/03/merge-pdf-files-using-c/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Copy-Clone custom object in C#</title>
		<link>http://www.wacdesigns.com/2008/08/05/copy-clone-custom-object-in-c/</link>
		<comments>http://www.wacdesigns.com/2008/08/05/copy-clone-custom-object-in-c/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 02:00:53 +0000</pubDate>
		<dc:creator>jf</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.wacdesigns.com/?p=83</guid>
		<description><![CDATA[This post relates how to Copy/Clone custom object in C# (Deep and Shallow Clone). In this example I will be having a base class that all my custom object will be inheriting from. Updates: After quiet some research on the subject i recently found some interesting articles on this subject and wanted to share them [...]]]></description>
			<content:encoded><![CDATA[<p>This post relates how to Copy/Clone custom object in C# (Deep and Shallow Clone).</p>
<p><span style="text-decoration: line-through;">In this example I will be having a base class that all my custom object will be inheriting from.</span></p>
<p><strong>Updates: </strong>After quiet some research on the subject i recently found some interesting articles on this subject and wanted to share them on this post.</p>
<h3>Object Cloning Using IL in C#</h3>
<blockquote><p>This subject is inspired on a session I followed on the TechDays 2008,<br />
that addressed the fact that IL (Intermediate Language) can be used to clone objects, among other things, and that it&#8217;s not evil at all, and it can be pretty performant also.</p>
<p>You only have to see that you don&#8217;t overuse it tho, because otherwise the readability of your code is reduced, which is not a good thing for the maintenance.<br />
And wrong usage of reflection (what IL is, or at least uses) can also result in poor performance.</p>
<p><em>Read more:</em><br />
<em><a href="http://whizzodev.blogspot.com/2008/03/object-cloning-using-il-in-c.html" target="_blank">http://whizzodev.blogspot.com/2008/03/object-cloning-using-il-in-c.html</a></em></p></blockquote>
<h3>C# Class For Making a Deep Copy Clone of an Arbitrary Object</h3>
<blockquote><p>Here is a C# class that can create a deep copy clone of an arbitrary object. The thing that&#8217;s special about it is that it should work for any class that extends it, so that you don&#8217;t need to re-write a custom clone() function for every child class (as it seems the C# framework creators would like). This does a deep copy so be careful about members that recursively include one another.</p>
<p>Another way of doing this would be to use serialization . . . I just personally thought the reflection package would be more elegant.</p>
<p><em>Read more: </em><br />
<em><a href="http://www.thomashapp.com/node/106" target="_blank">http://www.thomashapp.com/node/106</a></em></p></blockquote>
<h3>C# Object Clone Wars</h3>
<blockquote><p>Cloning C# objects is one of those things that appears easy but is actually quite complicated with many &#8220;gotchas.&#8221; This article describes the most common ways to clone a C# object.</p>
<p><strong>Shallow vs. Deep Cloning</strong></p>
<p>There are two types of object cloning: shallow and deep. A shallow clone copies the references but not the referenced objects. A deep clone copies the referenced objects as well.</p>
<div class="wp-caption alignnone" style="width: 410px"><a href="http://www.csharp411.com/c-object-clone-wars/"><img title="Shallow vs Deep Cloning" src="http://www.csharp411.com/wordpress/wp-content/uploads/2008/05/objectclone-thumb.jpg" alt="hallow vs Deep Cloning" width="400" height="195" /></a><p class="wp-caption-text">shallow vs Deep Cloning</p></div>
<p><em>Read more:<br />
<a href="http://www.csharp411.com/c-object-clone-wars/" target="_blank">http://www.csharp411.com/c-object-clone-wars/</a></em></p></blockquote>
<h3><strong>Clone C# Object</strong> using Serialization and De-serialization (Deep Clone)</h3>
<p>In this example i&#8217;ll be using Serialization and De-Serialization to make a deep clone of the Person Class.</p>
<p>You must import the following namespaces to start with.</p>
<pre>
using System;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.IO;
</pre>
<p>Let&#8217;s create a base class <strong>Person </strong>that all our other classes with inherit from. It will contain the following methods:</p>
<ul>
<li>ToXMLString() : Returns an XML version of the current object</li>
<li>Deserialize(XmlDocument xml, Type type) : De-serialize the current XMLDocument cast it to the current type</li>
<li>Serialize(object o) : Serialize the current object and outputs an XMLDocument</li>
<li>Clone(): Runs a Serialization and De-serialization and returns a clone of the current Object</li>
</ul>
<pre>
[Serializable()]
public abstract class Person
{
/// &lt;summary&gt;
/// To XML string.
/// &lt;/summary&gt;
/// &lt;returns&gt;&lt;/returns&gt;
public string ToXMLString()
{
XmlSerializer serializer = new XmlSerializer(this.GetType());
MemoryStream dataStream = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(dataStream, Encoding.UTF8);
serializer.Serialize(dataStream, this);
return writer.ToString();
}

/// &lt;summary&gt;
/// Deserializes an xml document back into an object
/// &lt;/summary&gt;
/// &lt;param name=&quot;xml&quot;&gt;The xml data to deserialize&lt;/param&gt;
/// &lt;param name=&quot;type&quot;&gt;The type of the object being deserialized&lt;/param&gt;
/// &lt;returns&gt;A deserialized object&lt;/returns&gt;
public static object Deserialize(XmlDocument xml, Type type)
{
XmlSerializer s = new XmlSerializer(type);
string xmlString = xml.OuterXml.ToString();
byte[] buffer = ASCIIEncoding.UTF8.GetBytes(xmlString);
MemoryStream ms = new MemoryStream(buffer);
XmlReader reader = new XmlTextReader(ms);
Exception caught = null;

try
{
object o = s.Deserialize(reader);
return o;
}

catch (Exception e)
{
caught = e;
}
finally
{
reader.Close();

if (caught != null)
throw caught;
}
return null;
}

/// &lt;summary&gt;
/// Serializes an object into an Xml Document
/// &lt;/summary&gt;
/// &lt;param name=&quot;o&quot;&gt;The object to serialize&lt;/param&gt;
/// &lt;returns&gt;An Xml Document consisting of said object&#039;s data&lt;/returns&gt;
public static XmlDocument Serialize(object o)
{
XmlSerializer s = new XmlSerializer(o.GetType());

MemoryStream ms = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(ms, new UTF8Encoding());
writer.Formatting = Formatting.Indented;
writer.IndentChar = &#039; &#039;;
writer.Indentation = 5;
Exception caught = null;

try
{
s.Serialize(writer, o);
XmlDocument xml = new XmlDocument();
string xmlString = ASCIIEncoding.UTF8.GetString(ms.ToArray());
xml.LoadXml(xmlString);
return xml;
}
catch (Exception e)
{
caught = e;
}
finally
{
writer.Close();
ms.Close();

if (caught != null)
throw caught;
}
return null;
}

/// &lt;summary&gt;
/// Creates a new object that is a copy of the current instance.
/// &lt;/summary&gt;
/// &lt;returns&gt;
/// A new object that is a copy of this instance.
/// &lt;/returns&gt;
public object Clone()
{
return Deserialize(Serialize(this), this.GetType());
}
}
</pre>
<p>Here are sample classes that herits from the abstract base class and clone operation are performed upon them.</p>
<pre>

public class Clerk: Person
{
private string position;

/// &lt;summary&gt;
/// Gets or sets the position.
/// &lt;/summary&gt;
/// &lt;value&gt;The position.&lt;/value&gt;
public string Position
{
get { return position; }
set { position = value; }
}
}

public class Developer: Person
{
private string skill;

/// &lt;summary&gt;
/// Gets or sets the skill.
/// &lt;/summary&gt;
/// &lt;value&gt;The skill.&lt;/value&gt;
public string Skill
{
get { return skill; }
set { skill= value; }
}
}
</pre>
<p>Using clone method.</p>
<pre>

public void UpdateSkills()
{
IList&lt;clerk&gt; clerkList = new ArrayList();
IList&lt;clerk&gt; newClerkList = new ArrayList();

foreach (Clerk clerk in clerkList)
{
newClerkList.Add((Clerk)clerk.Clone());
}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.wacdesigns.com/2008/08/05/copy-clone-custom-object-in-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ASP.NET: HyperLink and Label without Id attribute</title>
		<link>http://www.wacdesigns.com/2008/08/04/aspnet-hyperlink-and-label-without-id-attributes/</link>
		<comments>http://www.wacdesigns.com/2008/08/04/aspnet-hyperlink-and-label-without-id-attributes/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 02:00:54 +0000</pubDate>
		<dc:creator>jf</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.wacdesigns.com/?p=98</guid>
		<description><![CDATA[Today, I&#8217;ll talk a bit about how ASP.NET handles HTML rendering of controls such as &#60;asp:HyperLink&#62; and &#60;asp:Label&#62;.]]></description>
			<content:encoded><![CDATA[<p>Today, I&#8217;ll talk a bit about how ASP.NET handles HTML rendering of controls such as &lt;asp:HyperLink&gt; and &lt;asp:Label&gt;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wacdesigns.com/2008/08/04/aspnet-hyperlink-and-label-without-id-attributes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Exception: Collection was modified; enumeration operation may not execute.</title>
		<link>http://www.wacdesigns.com/2008/05/28/collection-was-modified-enumeration-operation-may-not-execute/</link>
		<comments>http://www.wacdesigns.com/2008/05/28/collection-was-modified-enumeration-operation-may-not-execute/#comments</comments>
		<pubDate>Wed, 28 May 2008 03:00:37 +0000</pubDate>
		<dc:creator>jf</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Exception]]></category>

		<guid isPermaLink="false">http://www.wacdesigns.com/?p=80</guid>
		<description><![CDATA[It&#8217;s been a while that i didn&#8217;t get this Exception, while working, and yesterday, while I was performing some test on a new module that I implemented i got this exception. I knew i did get it sometimes back last year, and managed to solve it. So here is one solution when you are dealing [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while that i didn&#8217;t get this Exception, while working, and yesterday, while I was performing some test on  a new module that I implemented i got this exception. I knew i did get it sometimes back last year, and managed to solve it. So here is one solution when you are dealing with this kind of issue:</p>
<pre>

IList&lt;Product&gt; productList = new List&lt;Product&gt;();
productList.Add(new Product("Some product 1");
productList.Add(new Product("Some product 2");
productList.Add(new Product("Some product 3");
productList.Add(new Product("Some product 4");
</pre>
<pre>

for(int i=(productList.Count -1); i &gt;= 0; i--)
{
//Perform Edit, Update, Delete Operation using for .. i loop in reverse order
}
</pre>
<p>There is a list of other solutions that can be found on the following websites:<br />
<a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=372532&amp;SiteID=1" target="_blank">http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=372532&amp;SiteID=1</a><br />
<a href="http://forums.asp.net/p/1147145/1861164.aspx" target="_self">http://forums.asp.net/p/1147145/1861164.aspx</a><br />
<a href="http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21585534.html" target="_blank">http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21585534.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wacdesigns.com/2008/05/28/collection-was-modified-enumeration-operation-may-not-execute/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Copy custom object in C#</title>
		<link>http://www.wacdesigns.com/2007/08/09/copy-custom-object-in-c/</link>
		<comments>http://www.wacdesigns.com/2007/08/09/copy-custom-object-in-c/#comments</comments>
		<pubDate>Thu, 09 Aug 2007 04:27:19 +0000</pubDate>
		<dc:creator>jf</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://www.wacdesigns.com/2007/08/09/copy-custom-object-in-c/</guid>
		<description><![CDATA[There are several ways to clone custom object in .NET. Using reflection to get information about each field and properties in the custom class, create a new instance and assign the proper value. Manually implementing the clone method and assign each field and method and then return a new object Using serialization and deserialization. I [...]]]></description>
			<content:encoded><![CDATA[<p>There are several ways to clone custom object in .NET.</p>
<ul>
<li>Using reflection to get information about each field and properties in the custom class, create a new instance and assign the proper value.</li>
<li>Manually implementing the  clone method and assign each  field and method and then return a new object</li>
<li>Using serialization and deserialization.</li>
</ul>
<p>I have tried the third method, that can be found <a title="Copy custom using serialization" href="http://www.thescripts.com/forum/thread214669.html" target="_blank">here</a>, it seems to be working fine for the time being, more test need to be done for performance overhead.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wacdesigns.com/2007/08/09/copy-custom-object-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  www.wacdesigns.com/category/net/c/feed/ ) in 0.80230 seconds, on Feb 4th, 2012 at 8:58 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 11th, 2012 at 8:58 am UTC -->
