netoops blog

Tuesday, 11 September 2012

Convert Text Document to PDF File


Description: 

About Classes used - 
#1: StreamReader class provides an access to read the data from Stream such as Text File.
#2: Document class allows creating a new instance for Creating PDF File.
#3: PdfWriter class, an instantaneous access to write a PDF document from an object of Document class. 
Namespace Required         -           System.IO,
iTextSharp,
iTextSharp.text,
iTextSharp.text.pdf 
Controls Used           -          
            1. TextBox Control (txtInput, txtOutput)
          2. Button Control (btnSelect, btnCreatePDF)         
Here I implemented the Code for converting Text Document into PDF Document using iTextSharp Tool.           
The Code:
1. Select the Text File (code for “Select File” Button).           
using (OpenFileDialog file = new OpenFileDialog()){    //Show the Dialog Box & Select the File    file.ShowDialog();    //Assign Input FileName to TextBox    txtInput.Text = file.FileName;}
//Assign Output FileName to TextBox
txtOutput.Text = (txtInput.Text).Replace(".txt", ".pdf");
Listing 1
2. Convert Text File into a PDF File (code for “Create PDF” Button).
//Read the Data from Input File
StreamReader rdr = new StreamReader(txtInput.Text);
//Create a New instance on Document Class
Document doc = new Document();
//Create a New instance of PDFWriter Class for Output File
PdfWriter.GetInstance(doc, new FileStream(txtOutput.Text,FileMode.Create));
//Open the Document
doc.Open();
//Add the content of Text File to PDF File
doc.Add(new Paragraph(rdr.ReadToEnd()));
//Close the Document
doc.Close();
MessageBox.Show("Conversion Successful....");
//Open the Converted PDF File
System.Diagnostics.Process.Start(txtOutput.Text);
Listing 2
3. Now execute the Application and see the result (Figure 1).  
Intended Result:
New Picture (1).png
Figure 1 

Saturday, 8 September 2012

Your Colorful Visual Studio 2012 with the Color Theme Editor (VS2010 colors, too)

The stock Visual Studio 2012 gray color scheme is growing on me. Sue me. When you're writing code you usually focus on the code so I'm more concerned with the colors of the code than the chrome.

Here's my default, which is the VS2012 defaults with larger fonts.
VS2012 with the default color scheme
Here is Visual Studio 2012 again, except this time I've used Matthew Johnson's Visual Studio 2012 Color Theme Editor and applied the Blue theme:
VS2012 with VS2010 colors
Here it is again with the ALL CAPS registry setting turned off:
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\General\SuppressUppercaseConversion
REG_DWORD value: 1
Now you're pretty much back to the VS2010 look and feel. I've zoomed in here to make it clear.
Visual Studio 2012 with the ALL CAPS menu removed and the VS2010 colors restored
Go nuts! You can make and share custom themes yourself! With this add-in you can customize a lot more than the default installation allows:
A wide range of color options
Have fun! Go get Matthew Johnson's Visual Studio 2012 Color Theme Editor now.

Friday, 7 September 2012

Auto Refresh Update GridView In Asp.Net Ajax With Timer


This Example describes How To Auto Refresh Or Update GridView Automatically At Regular Interval In Asp.Net Using Ajax And Timer.

Add GridView And Timer control inside UpdatePanel on the page and set Interval property to desired value in miliseconds. I have set it to 5000 (5 Seconds).

HTML SOURCE

   1:  <asp:ScriptManager ID="ScriptManager1" runat="server"/>
   2:  <asp:UpdatePanel ID="UpdatePanel1" runat="server">
   3:  <ContentTemplate>
   4:   
   5:  <asp:Timer ID="AutoRefreshTimer" runat="server" 
   6:             Interval="5000" 
   7:             ontick="AutoRefreshTimer_Tick"/>
   8:                              
   9:  <asp:GridView ID="GridView1" runat="server" 
  10:                AutoGenerateColumns="False" 
  11:                DataSourceID="SqlDataSource1">
  12:  <Columns>
  13:  <asp:BoundField DataField="FirstName" HeaderText="FirstName"/>
  14:  <asp:BoundField DataField="LastName" HeaderText="LastName"/>
  15:  <asp:BoundField DataField="Location" HeaderText="Location"/>
  16:  </Columns>
  17:  </asp:GridView>
  18:   
  19:  <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
  20:  ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
  21:  SelectCommand="SELECT [FirstName], [LastName], [Location] 
  22:                 FROM [Details]">
  23:  </asp:SqlDataSource>
  24:   
  25:  <asp:Label ID="lblMsg" runat="server"/>
  26:  </ContentTemplate>
  27:  </asp:UpdatePanel>


Rebind GridView In Tick Event of Timer to refresh.

C#




1protected void AutoRefreshTimer_Tick(object sender, EventArgs e)
2    {
3        GridView1.DataBind();
4        lblMsg.Text = "Last Updated at " + DateTime.Now;
5    }


Image below shows the implementation.


Automatically Refresh Update Asp.Net GridView with Ajax Timer
Related Posts Plugin for WordPress, Blogger...