Skip to main content


Showing posts from August, 2011

How to compress and decompress data in c#

In this post,I will show you how to compress and decompress data in c# using GzipStream class.Below is the code for the same
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.IO.Compression; namespace CompressDecompress { class Program { conststring CompressFilePath = @"C:\temp\"; conststring Filename = @"C:\temp\data.txt"; privateconststring DeCompressFilePath = @"C:\temp\data1.txt"; staticvoid Main(string[] args) { Compress(Filename); Decompress(CompressFilePath); } privatestaticvoid Decompress(string compressFilePath) { using (FileStream inputStream = new FileStream(compressFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { using (FileStream outputStream = new FileStream(DeCompressFilePath, FileMode.Create, FileAccess.ReadWrite)) { using (GZipStream g…

How to read pdf document properties in

In this post, I will show you how to read the pdf document properties in we know that there is no- such  in-built class in .net framework that read the pdf document.So,for this demo,I will used third-party library iTextSharp.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PdfPropertiesReader.aspx.cs" Inherits="PdfPropertiesReader" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"""><htmlxmlns=""><headrunat="server"><title></title></head><body><formid="form1"runat="server"><div><divid="pdfProperties"runat="server"></div></div><asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Read Pdf Properties"/></form>&…

How to convert IEnumerable to Html table in

In this post I will show how to convert IEnumerable to string (Html table).Assume you have a customer class which has three properties named FirstName,LastName and Age.Now,you want to display customer collection on UI.
For this I have created following method which retrives propertyname and value dynamically (using reflection) and return result as string
public static string ToHtmlTable(IEnumerable list, string tableSyle, string headerStyle, string rowStyle, string alternateRowStyle)<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"""><htmlxmlns=""><headrunat="server"><title></title><styletype="text/css"> .headerStyle { background-color: #abc;…

How to fetch header info from given url

In this post I will show how to fetch header info from given url using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Text; namespace SNIPPET_CS { publicclass HeaderInfo { publicstring Key { get; set; } publicstring Value { get; set; } publicstatic List<HeaderInfo> GetHttpResponseHeaders(string url) { List<HeaderInfo> headerList = new List<HeaderInfo>(); WebRequest webRequestObject = WebRequest.Create(url); WebResponse responseObject = webRequestObject.GetResponse(); if (responseObject != null) { headerList.AddRange(from string headerKey in responseObject.Headers select new HeaderInfo() { Key = headerKey, Value = responseObj…

How to send output of console application to file

In this example,I will show how to send console output to file in c# using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace SNIPPET_CS { class Program { staticvoid Main(string[] args) { ConsoleOutput(); Console.WriteLine("Console output saved successfully"); Console.ReadLine(); } privatestaticvoid ConsoleOutput() { conststring applicationPath = @"D:\Windows\System32\ipconfig.exe"; //string ApplicationArguments = "-c -x";// Create a new process object Process processObj = new Process(); // StartInfo contains the startup information of// the new process processObj.StartInfo.FileName = applicationPath; //ProcessObj.StartInfo.Arguments = ApplicationArguments;// These two optional flags ensure that no DOS window// appear…