Let's Talk About .NET, Java, and Various File Formats!

Mozilla Thunderbird is a very good email client and it is free too. I like it a lot as it allows to setup multiple email accounts without worrying about “Profiles” unlike Microsoft Outlook. It is very light and easy to use. It also provides features to compact your local database or setup limit on the emails to keep in your local folder.

I had only one problem while setting Gmail. Whenever I configured my Gmail account with Thunderbird, it started downloading all the older emails which I had read already. As I had a lot of emails in my Gmail account, it would take a lot of time to download older emails.

Well, at last I figured this out! I had to make a few changes in my ‘Gmail Settings’.  You can also follow the below steps to download only new messages from your Gmail account when setting Thunderbird with POP3:

  • Open your Gmail account.
  • Go to Settings
  • Select ‘Forwarding and POP/IMAP’
  • Under ‘POP Download’ Select ‘Enable POP for mail that arrives from now on’
  • To retain original copy, Select ‘keep Gmail’s copy in the inbox’

Please also see the following snapshot to give you a better idea:

Download only new messages from Gmail in Thunderbird using POP3

I hope this helps you in resolving the issue of downloading only new messages from the Gmail account in Thunderbird via POP3.


Reading a file from the disk into the MemoryStream is a very common requirement while working with files in your .NET applications. It is important to read the files to MemoryStream when you want to process the file inside memory. For example, when you want to render a file from the server to the browser. This is very simple and you can use the following code snippet to read the file contents from the disk to the MemoryStream.

C# Code Snippet:

//open file from the disk (file path is the path to the file to be opened)
using (FileStream fileStream = File.OpenRead(filePath))
//create new MemoryStream object
MemoryStream memStream = new MemoryStream();
//read file to MemoryStream
fileStream.Read(memStream.GetBuffer(), 0, (int)fileStream.Length);

VB.NET Code Snippet:

‘open file from the disk (file path is the path to the file to be opened)
Using fileStream As FileStream = File.OpenRead(filePath)
‘create new MemoryStream object
Dim memStream As New MemoryStream()
‘read file to MemoryStream
fileStream.Read(memStream.GetBuffer(), 0, CInt(Fix(fileStream.Length)))
End Using

These guys have made a parody of ‘Why this kolaveri di’. It’s very funny. Software guys are really gonna enjoy this. 🙂

In my previous post titled ‘Learn and Understand PDF Structure‘, I shared some details regarding the structure of the PDF file. Sometimes, we also need to view the internal structure of the PDF files in order to understand the objects of the PDF file and their relationships. In this post, I’ll share how you can view this internal structure in detail easily.

You can either use Adobe Acrobat to view the PDF structure or a free tool called PDFXplorer. If you want to use Acrobat to view the internal structure, you can use Preflight option to do that. In Acrobat X, you can access this option from Tools -> Print Production -> Preflight.


The following snapshot shows you how the internal PDF structure will look like in the Acrobat.


As I mentioned earlier, there is a free tool as well to view the internal PDF structure named PDFXplorer. You can download it from this link. It is very simple tool which gives you only one option to browse a particular PDF and then view its internal structure. You can see in the following snapshot that how the internal structure will look like in this tool.


I hope this post helps you to view the internal PDF structure.

In general terms, accessibility is used to describe the degree to which something is available to as many people as possible. However, it is often used to focus on people with disabilities and their right of access to entities. Assistive technologies are helping the people with special needs in all the areas of life. This is true in the field of computer and internet as well, so that this technology could also be made accessible to the people with disabilities.

While making the computers and web accessible to the people with such special needs, it is important to make the contents and data accessible to the users; PDF files are also part of these contents. When we want to make a PDF accessible, it means we need to follow certain standards while creating or editing PDF files, so that the contents of these PDF files can be accessed by the assistive technologies and provided to the users.

These standards include making the contents completely tagged and marking the document tagged as well, defining document language, providing accessible font encoding, bookmarks, and consistent heading structure etc. You can find more details about accessible PDF files in section 14.9 of PDF Specification Reference. And in order to understand the accessibility for the contents published on the web, you need to check out W3C document Web Content Accessibility Guidelines.

We have seen a little bit about accessibility and accessible PDF files. Now, let’s have a look at a free tool, called PAC (PDF Accessibility Checker) , provided by “Access for All” Foundation. This is a very simple tool to test the technical accessibility of the PDF documents. You only need to download and extract the tool, and run PAC.exe to check the PDF.PDF Accessibility Checker

Simply browse the PDF file you want to test for accessibility and press Start Check button. It will show you all the passed results in the testing criteria.

In the .NET applications, we some times need to render the PDF files to the browser using our code — C# or VB.NET etc. It’s not a big deal! You only need to use Response object to send the file to the browser. The only thing you need to take care of is the use of proper methods and attributes.

First of all, we need to save the PDF document to a MemoryStream object. For example, we have a MemoryStream object named outStream and we need to render it to the browser. The following code snippet can be used to render the file:

//create new MemoryStream object and add PDF file’s content to outStream.
MemoryStream outStream = new MemoryStream();

//specify the duration of time before a page cached on a browser expires
Response.Expires = 0;

//specify the property to buffer the output page
Response.Buffer = true;

//erase any buffered HTML output

//add a new HTML header and value to the Response sent to the client
Response.AddHeader(“content-disposition”, “inline; filename=” + “output.pdf”);

//specify the HTTP content type for Response as Pdf
Response.ContentType = “application/pdf”;

//write specified information of current HTTP output to Byte array

//close the output stream

//end the processing of the current page to ensure that no other HTML content is sent

You need to use AddHeader method of Response object to add header and value to the response sent to the client. Content-Disposition response header field is used to convey additional information about how to process the response, and also to attach additional metadata, such as filename. The PDF will be viewed in the PDF viewer plugin installed for the browser. You can see a practical example of rendering the PDF file to browser in Aspose.Pdf Demo. In order to view the source code, please click on the Source tab.

ZIP file format allows you to make an archive of a set of files and compress those files in the package. The Zip file may contain the files without any compression, just for the sake of archive. The Zip format supports many algorithms. Zip files use .zip extension and ‘application/zip’ MIME type.

There are many software and tools for creating Zip files manually. However, software developers sometimes need to create the Zip files using their code. In this post, I’ll show you how to create Zip package using .NET application. I’m going to use C# for creating the sample for this post.

Although, creating Zip files from scratch and working with related algorithms is very complex and time consuming task. However, there are some free libraries which you can use in your code. One such free library is DotNetZip library. You can download this free library from codeplex.com. This library helps you Zip and Unzip files and folders in your .NET code. You can use this library in a variety of .NET applications.

In order to create a Zip file, you need to find the Ionic.Zip DLL which you can find in Tools folder inside the DotNetZip package you downloaded from codeplex.com. Once you have added the reference to this DLL, use the Ionic.Zip namespace in your code as shown below:

//Ionic library to create Zip files
using Ionic.Zip;

After that you can use the following code to Zip the files and folders into a single package:

//create ZipFile class
ZipFile zipFile = new ZipFile();
//add whole directory in the Zip package
zipFile.AddDirectory(@”C:\Files to Zip\html”,”/package/html”);
zipFile.AddDirectory(@”C:\Files to Zip\data”, “/package/data”);
//add particular file in the package
zipFile.AddFile(@”C:\Files to Zip\main.txt”,”/package/”);
//save output Zip file

AddDirectory method allows you to add a whole directory in a Zip file. First parameter is the path to the source directory and the second parameter represents the path in the Zip archive. In this example, I have mapped html and data folders from the source directory to the folders in the package directory in Zip archive. Similarly, AddFile method allows you to add a single file in the Zip package. In this case, I have added main.txt file in the root folder inside the archive.Finally, you can save the output PDF with the help of Save method of ZipFile class.

In this post, you have got an idea that how simple it is to create a Zip package in your .NET applications with the help of free Zip library. In my next post, I’ll share some other good programming tip with you guys.