Saturday, 22 February 2014

How can make PDF file in Vb.net

How can make PDF file in Vb.net

Imports iTextSharp.text
Imports System.IO
Imports iTextSharp.text.html.simpleparser
Imports iTextSharp.text.pdf
Please Add Above namesapce And Add iTextSharp .dll file in Add Reference,& Edit This Event
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="pdf.aspx.vb" Inherits="pdf"
EnableEventValidation="false" %>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Response.ContentType = "application/pdf"
            Response.AddHeader("content-disposition", "attachment;filename=SandeepPage.pdf")
            Response.Cache.SetCacheability(HttpCacheability.NoCache)
            Dim sw As New StringWriter()
            Dim hw As New HtmlTextWriter(sw)
            Me.Page.RenderControl(hw)
            Dim sr As New StringReader(sw.ToString())
            Dim pdfDoc As New Document(PageSize.A4, 10.0F, 10.0F, 100.0F, 0.0F)
            Dim htmlparser As New HTMLWorker(pdfDoc)
            PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
            pdfDoc.Open()
            htmlparser.Parse(sr)
            pdfDoc.Close()
            Response.Write(pdfDoc)
            Response.[End]()
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try
End Sub

Fetch the data from Excel File at GridView

Fetch the data from Excel File at GridView

1.use this name space:-Imports System.Globalization
2.Add the Excel file in Solution Explorer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        fillgried()
    End Sub
  
  Function fillgrid()
        Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("Customers1.xlsx") + ";Extended Properties='Excel 12.0 Xml;HDR=YES;'"
        Dim query As String = "SELECT * FROM [customers$]"
        Dim excelDataSet As DataSet = New DataSet()
        excelDataSet.Locale = CultureInfo.InvariantCulture
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(query, strConn)
        da.Fill(excelDataSet)
        GridView1.DataSource = excelDataSet.Tables(0)
        GridView1.DataBind()
    End Function

How do we read data from a XML file and display it in a DataGrid ?

How do we read data from a XML file and display it in a DataGrid ?

using ReadXML method
DataSet MyDataset= new DataSet ();
MyDataset.ReadXml (Server.MapPath ("sample.xml"));
MyDataGrid.DataSource =MyDataset;
MyDataGrid.DataBind();

Show date And Time in many format

Show date And Time in many format

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class CurrentDate : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = System.DateTime.Now.ToString();
Label3.Text = System.DateTime.Now.ToLongDateString();
Label4.Text = System.DateTime.Now.ToLongTimeString();
Label5.Text = System.DateTime.Now.ToShortDateString();
Label6.Text = System.DateTime.Now.ToShortTimeString();
}
}

Use Color Code in VB.Net

Use Color Code in VB.Net

 btn.BackColor =Color .FromArgb (192,192,0)

Find Second Max in SQL

Find Second Max in SQL

SELECT TOP 1 * From (select Top 2 * from complaint_log ORDER BY s_no DESC)a ORDER BY s_no   

clear ALL textboxes and label

clear ALL textboxes and label

For Each ctrl In Controls
                If TypeOf ctrl Is TextBox Or TypeOf ctrl Is Label Then
                    ctrl.Text = String.Empty
                End If
            Next