Monday, 11 August 2014

Build configuration dropdown

Missing build configuration dropdown in Visual Studio 2008

 
 
 
 
 
 
My project is using Microsoft Visual Studio 2008 for development. For some strange reason the build configuration dropdown does not show up by default in the IDE.
A screenshot of the build configuration dropdown present in the IDE
I found the following procedure online and very helpful. It describes how to get this useful dropdown visible:
  1. In Visual Studio 2008, click “Tools” -> “Options”
  2. Under “Projects and Solutions” -> “General”, check “Show advanced build options”, and click “OK”
  3. Right click anywhere in the blank space of the toolbar and click “Customize…”
  4. In “Commands” tab, select “Build” in “Categories”.
  5. Scroll the right listbox to the bottom and drag “Solution Configurations” to the toolbar

Thursday, 10 July 2014

Restoring Database Using Query

RESTORE DATABASE [Monitoring_Agency]
FROM DISK = N'D:\Monitoring_Agency.bak'
WITH FILE = 1,
MOVE N'Monitoring_Agency'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Monitoring_Agency.mdf',
MOVE N'Monitoring_Agency_Log'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Monitoring_Agency.ldf',
NOUNLOAD, REPLACE, STATS = 10
GO

Thursday, 26 June 2014

Find Device Plugged In Or Not


    Public Shared Function Populate_list() As Integer
        Dim searcher As New ManagementObjectSearcher("SELECT Name FROM  Win32_pnpentity where Name like 'Concel%'")
        Return searcher.Get().Count
    End Function
 



If Store.Populate_list() = 0 Then
            MsgBox("Diacorder Not Connected Properly." & vbCrLf & "Connect It Properly and Then Proceed Further.")
            Return
        End If
        If funcs.CheckIfRunning("Diacorder") = True Then funcs.KillProcess("Diacorder")

Tuesday, 24 June 2014

Crystal Reports In Windows Forms With Parameters

In this example i am explaining how to create Crystal Reports In Winforms Or Windows Forms Application With Parameters from user to filter report using C#.NET and VB.NET 


Crystal Reports In Winforms Or Windows Forms Application With Parameters
For this i have created two tables in database named Employees and Projects and fetching data from both tables

I've grouped results by Department name using group expert in crystal reports and put a dropdown on the form to select project name to display related report.

Employee table schema 

ID    int   
FirstName    varchar(50)
LastName    varchar(50)    
Department    varchar(50)    
ProjectID    numeric(18, 0)   
Expenses    money    


Projects table schema 

ProjectID    numeric(18, 0)    
ProjectName    varchar(50)   






Create a new project in VS and go to solution explorer and add new item > crystal report.

Select Blank report option from the wizard window
reate a new project in VS and go to solution explorer and add new item > crystal report.
Select Blank report option from the wizard window

 
Now click on CrystalReports menu and select DataBase Expert 
Now in next window expand Create new connection section and OLEDB(ADO) and in next window select SQL Native Client
Enter you SQL Server name , username and password , select database name from the dropdown and click on ok
In next window expand to find your tables and add them in right pane
Click OK to finish

Now Right Click on Group Name Fields in Field Explorer and Select Group Expert.
In group expert box select the field on which you want data to be grouped.

 
  
Design your report by dragging the fields in section3 (Details) 
my design look like this  
In the form add a combobox and drag and drop CrystalReport Viewer from toobox. click on smart tag and choose the report we created earlier (CrystalReport1.rpt) 
Form look like this 
When we build and rum this report , it asks for Database login username and password , we need to provide database username and password in code behind.
 we need to write code in code behind to filter report based on user selected value or value provided by user .
VB.NET code behind
//Code to populate dropdown
//Fill dropdown in form_Load event by calling 
//function written below
private void FillDropDown()
{
 SqlConnection con = new SqlConnection
       (ConfigurationManager.AppSettings["myConnection"]);
 SqlCommand cmd = new SqlCommand
("Select distinct ProjectID,ProjectName from Projects", con);
 con.Open();
 DataSet objDs = new DataSet();
 SqlDataAdapter dAdapter = new SqlDataAdapter();
 dAdapter.SelectCommand = cmd;
 dAdapter.Fill(objDs);
 cmbMonth.DataSource = objDs.Tables[0];
 cmbMonth.DisplayMember = "ProjectName";
 cmbMonth.ValueMember = "ProjectID";
 cmbMonth.SelectedIndex = 0;
}
private void cmbMonth_SelectedIndexChanged
              (object sender, EventArgs e)
{
      //Create object of report 
CrystalReport1 objReport = new CrystalReport1();

    //set database login information
objReport.SetDatabaseLogon
    ("amit", "password", @"AVDHESH\SQLEXPRESS", "TestDB");

//write formula to pass parameters to report 
crystalReportViewer1.SelectionFormula 
    ="{Projects.ProjectID} =" +cmbMonth.SelectedIndex;
crystalReportViewer1.ReportSource = objReport;
}
      
  






Copy a table across two database in the same Sql Server.

select * into [destination database.dbo.destination table]

from [source database.dbo.source table]
 
Example:
select * into Mydatabase2.dbo.employee_backup
from mydatabase1.dbo.employee

Sql Server: How to copy a table?

This is the simplest way to copy a table into another (new) table in the same SQL Server database. This way of copying does not copy constraints and indexes.




select * into [destination table] from [source table]
Example:
Select * into employee_backup from employee

We can also select only a few columns into the destination table like below

select col1, col2, col3 into [destination table]from [source table]
Example:
Select empId, empFirstName, empLastName, emgAge into employee_backup fromemployee

Use this to copy only the structure of the source table.

select * into [destination table] from [source table] where 1 = 2
Example:
select * into employee_backup from employee where 1=2

Use this to copy a table across two database in the same Sql Server.





select * into [destination database.dbo.destination table] from [source database.dbo.source table]
Example:
select * into Mydatabase2.dbo.employee_backup
from mydatabase1.dbo.employee

Thursday, 8 May 2014

Export Gridview Data To Excel

 Dim xlapp As Microsoft.Office.Interop.Excel.Application
                Dim misValue As Object = System.Reflection.Missing.Value
                Dim xlworkbook As Microsoft.Office.Interop.Excel.Workbook
                Dim xlworksheet As Microsoft.Office.Interop.Excel.Worksheet
                If grdlogdetail.Rows.Count = 0 Then Exit Sub
                If grdlogdetail.Rows.Count >= 1 Then
                    Dim path = "d:\CallLog"
                    Dim dr As New DirectoryInfo(path)
                    If Not dr.Exists Then
                        Directory.CreateDirectory(path)
                    End If
                    Dim finalpath As String = path & "\" & "Operator's Report.xls"
                    xlapp = New Microsoft.Office.Interop.Excel.Application
                    xlworkbook = xlapp.Workbooks.Add(misValue)
                    'xlworksheet = xlworkbook.Sheets("sheet1")
                    xlworkbook = xlapp.Workbooks.Add(misValue)
                    xlworksheet = xlworkbook.Worksheets(1)
                    xlworksheet.Cells(1, 1).Font.Size = 20
                    xlworksheet.Cells(1, 1).Font.Bold = True
                    xlworksheet.Cells(1, 1).Font.Color = Color.Red

                    xlworksheet.Cells(1, 1) = "Operator's CallLog "
                    ' xlworksheet.Cells(1, 1).Font.Color = Color.Red
                    xlworksheet.Cells(2, 1) = "Name"
                    xlworksheet.Cells(2, 2) = "Days On Job"
                    xlworksheet.Cells(2, 3) = "No Of Calls"
                    xlworksheet.Cells(2, 4) = "Average(Calls/Day)"
                    xlworksheet.Rows(2).Font.Bold = True
                    xlworksheet.Rows(2).Font.Size = 15
                    xlworksheet.Rows(2).Font.Color = Color.Blue

                    xlworksheet.Rows(2).WrapText = True

                    xlworksheet.Columns(1).ColumnWidth = 23
                    xlworksheet.Columns(2).ColumnWidth = 17
                    xlworksheet.Columns(3).ColumnWidth = 17
                    Dim j As Integer = 3
                    For i = 0 To grdlogdetail.RowCount - 1
                        xlworksheet.Cells(j, 1) = grdlogdetail.Rows(i).Cells(0).Value.ToString()
                        xlworksheet.Cells(j, 1).WrapText = True
                        xlworksheet.Cells(j, 2) = grdlogdetail.Rows(i).Cells(1).Value.ToString()
                        xlworksheet.Cells(j, 3) = Convert.ToString(grdlogdetail.Rows(i).Cells(2).Value)
                        xlworksheet.Cells(j, 4) = Convert.ToString(grdlogdetail.Rows(i).Cells(3).Value)
                        ' xlworksheet.Cells(j, 4) = grdlogdetail.Rows(i).Cells(3).Value.ToString()
                        j = j + 1
                    Next
                    xlworksheet.Rows(j - 1).Font.Bold = True
                    xlworksheet.Rows(j - 1).Font.Size = 11
                    ' xlworksheet.Rows(j - 1).Font.Color = Color.Blue
                    xlworksheet.Rows(2).AutoFilter()
                    xlworksheet.Rows(3).Activate()
                    xlworksheet.Rows(2).WrapText = True
                    xlworksheet.PageSetup.PrintGridlines = True
                    xlapp.ActiveWindow.FreezePanes = True
                    xlworksheet.PageSetup.Orientation = Excel.XlPageOrientation.xlLandscape
                    Dim fileinfo As New DirectoryInfo(path)
                    For Each ff In fileinfo.GetFiles()
                        If ff.Exists Then
                            ff.Delete()
                        End If
                    Next
                    xlworkbook.SaveAs(finalpath)
                    Dim proc1 As System.Diagnostics.Process
                    For Each proc1 In System.Diagnostics.Process.GetProcessesByName("EXCEL")
                        proc1.Kill()
                    Next
                    Dim res As MsgBoxResult
                    res = MsgBox("Process Completed.Would you like to Open File?", MsgBoxStyle.YesNo)
                    If res = MsgBoxResult.Yes Then
                        Process.Start(finalpath)
                    End If
                End If
            Case "U"
                Dim xlapp As Microsoft.Office.Interop.Excel.Application
                Dim misValue As Object = System.Reflection.Missing.Value
                Dim xlworkbook As Microsoft.Office.Interop.Excel.Workbook
                Dim xlworksheet As Microsoft.Office.Interop.Excel.Worksheet
                If grdlogdetail.Rows.Count = 0 Then Exit Sub
                If grdlogdetail.Rows.Count >= 1 Then
                    Dim path = "d:\CallLog"
                    Dim dr As New DirectoryInfo(path)
                    If Not dr.Exists Then
                        Directory.CreateDirectory(path)
                    End If
                    Dim finalpath As String = path & "\" & "University Report.xls"
                    xlapp = New Microsoft.Office.Interop.Excel.Application
                    xlworkbook = xlapp.Workbooks.Add(misValue)
                    'xlworksheet = xlworkbook.Sheets("sheet1")
                    xlworkbook = xlapp.Workbooks.Add(misValue)
                    xlworksheet = xlworkbook.Worksheets(1)
                    xlworksheet.Cells(1, 1).Font.Size = 20
                    xlworksheet.Cells(1, 1).Font.Bold = True
                    '  xlworksheet.Cells(1, 1).Font.Color = Color.Red

                    xlworksheet.Cells(1, 1) = "University Report"
                    ' xlworksheet.Cells(1, 1).Font.Color = Color.Red
                    xlworksheet.Cells(2, 1) = "Name Of University"
                    xlworksheet.Cells(2, 2) = "State"
                    xlworksheet.Cells(2, 3) = "No Of Contacts"
                    xlworksheet.Rows(2).Font.Bold = True
                    xlworksheet.Rows(2).Font.Size = 15
                    ' xlworksheet.Rows(2).Font.Color = Color.Blue

                    xlworksheet.Rows(2).WrapText = True

                    xlworksheet.Columns(1).ColumnWidth = 23
                    xlworksheet.Columns(2).ColumnWidth = 17
                    xlworksheet.Columns(3).ColumnWidth = 17
                    Dim j As Integer = 3
                    For i = 0 To grdlogdetail.RowCount - 1
                        xlworksheet.Cells(j, 1) = grdlogdetail.Rows(i).Cells(0).Value.ToString()
                        xlworksheet.Cells(j, 1).WrapText = True
                        xlworksheet.Cells(j, 2) = grdlogdetail.Rows(i).Cells(1).Value.ToString()
                        xlworksheet.Cells(j, 3) = Convert.ToString(grdlogdetail.Rows(i).Cells(2).Value)
                        ' xlworksheet.Cells(j, 4) = grdlogdetail.Rows(i).Cells(3).Value.ToString()
                        j = j + 1
                    Next
                    xlworksheet.Rows(j - 1).Font.Bold = True
                    xlworksheet.Rows(j - 1).Font.Size = 11
                    ' xlworksheet.Rows(j - 1).Font.Color = Color.Blue
                    xlworksheet.Rows(2).AutoFilter()
                    xlworksheet.Rows(3).Activate()
                    xlworksheet.Rows(2).WrapText = True
                    xlworksheet.PageSetup.PrintGridlines = True
                    xlapp.ActiveWindow.FreezePanes = True
                    xlworksheet.PageSetup.Orientation = Excel.XlPageOrientation.xlLandscape
                    Dim fileinfo As New DirectoryInfo(path)
                    For Each ff In fileinfo.GetFiles()
                        If ff.Exists Then
                            ff.Delete()
                        End If
                    Next
                    xlworkbook.SaveAs(finalpath)
                    Dim proc1 As System.Diagnostics.Process
                    For Each proc1 In System.Diagnostics.Process.GetProcessesByName("EXCEL")
                        proc1.Kill()
                    Next
                    Dim res As MsgBoxResult
                    res = MsgBox("Process Completed.Would you like to Open File?", MsgBoxStyle.YesNo)
                    If res = MsgBoxResult.Yes Then
                        Process.Start(finalpath)
                    End If
                End If
        End Select

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

Print Character using Asc value

Print Character using Asc value

For i = 97 To 122
                k &= "(" & Chr(i) & ")" & vbCrLf
              Label4.Text = k
            Next
            i += 1

VB.NET Generate a random string of numbers and letters

VB.NET Generate a random string of numbers and letters

Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn.Click
        Dim s As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
        Dim r As New Random
        Dim sb As New StringBuilder
        For i As Integer = 1 To 4
            Dim idx As Integer = r.Next(0, 35)
            sb.Append(s.Substring(idx, 1))
        Next
        Label2.Text = sb.ToString
    End Sub

Create Folder In VB.net

Create Folder In VB.net

 Private Sub Ok_Button_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ok_Button.Click
                ' Check if folder exists, if not: create it
        If Not Directory.Exists("D:\" & "SandeepKumarYadav") Then
            Directory.CreateDirectory("D:\" &"SandeepKumarYadav")
            ' Folder created message
            MessageBox.Show("Folder created!", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            ' Folder already exists
            MessageBox.Show("Folder already exists!", "", MessageBoxButtons.OK, MessageBoxIcon.Stop)
        End If
    End Sub

Opening A URL in vb.net

Opening A URL in vb.net

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        System.Diagnostics.Process.Start("http://www.sandeepsky.blogspot.in")
    End Sub

upload Image in Gridview vb.net

upload Image in Gridview vb.net

Import System.IO

Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        Try
            Dim s As String = FileUpload1.PostedFile.FileName
            Dim s1 As String = Path.GetFileName(s)
            FileUpload1.PostedFile.SaveAs(Server.MapPath("img/" + s1))
            Dim s2 As String = "../img/" + s1
            da = New SqlDataAdapter("insert into move(title,director)values('" + TextBox1.Text + "','" + s2 + "')", cn)
            ds = New DataSet()
            da.Fill(ds)
            GridView2.DataSource = ds
            GridView2.DataBind()
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try
    End Sub

Validate TxtBox For Mobile Number

Validate TxtBox For Mobile Number

Private Sub TxtNo_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtNo.KeyPress
        If Asc(e.KeyChar) <> 8 Then
            If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Or TxtNo.Text.Length > 9 Then
                e.Handled = True
            End If
        End If
    End Sub

Select/UnSelect all items in checkboxlist in vb.net

Select/UnSelect all items in checkboxlist in vb.net

 Private Sub chk_crimeName_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles chk_crimeName.ItemCheck
     

 If e.Index = 0 Then
            If e.NewValue = CheckState.Checked Then
                For i As Integer = 1 To chk_crimeName.Items.Count - 1
                    chk_crimeName.SetItemCheckState(i, CheckState.Checked)
                Next
            ElseIf e.NewValue = CheckState.Unchecked Then
                For i As Integer = 1 To chk_crimeName.Items.Count - 1
                    chk_crimeName.SetItemCheckState(i, CheckState.Unchecked)
                Next
            End If
        End If

    End Sub

Select/UnSelect item of Listbox select On checkboxlist
Dim item1 As String = chk_district.SelectedIndex
            If e.NewValue = CheckState.Checked Then
                ListBox1.SelectedIndex = e.Index
            Else
                ListBox1.SetSelected(e.Index, False)
            End If

Retrieve the ValueMember of the DisplayMember items in checklistbox

Retrieve the ValueMember of the DisplayMember items in checklistbox

Public Sub chklistbox()

        Dim dr As DataTable = objdb.getdata("select district_name,district_id from district_master where state_id='" & "9" & "'")
        If dr.Rows.Count > 0 Then
            CheckedListBox1.DataSource = dr
            CheckedListBox1.DisplayMember = "district_name"
            CheckedListBox1.ValueMember = "district_id"
            CheckedListBox1.Text = Nothing
            dr = Nothing
        Else
            CheckedListBox1.DataSource = Nothing
            CheckedListBox1.Text = Nothing
        End If
    End Sub

when you assign properties value member and display member you can retrieve its value using :

 Label9.Text = CheckBoxList1.SelectedItem.ToString()
        Label8.Text = CheckedListBox1.SelectedValue.ToString()

Find integer from string

Find integer from string

 Dim Res As String
Dim str As String = "Faheem786Ahmad"
        For Each c As Char In str
            If IsNumeric(c) Then
                Res = Res & c
            End If
        Next
        MessageBox.Show(Res)

Create Excel File in vb.net

Create Excel File in vb.net

Private Sub cmdexcel_Click()
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet

Dim row As Long
Set xlapp = New Excel.Application
Set xlbook = xlapp.Workbooks.Add
Set xlsheet = xlbook.Worksheets(1)
row = 4
With xlsheet

If optdatewise.Value = True Then
.Cells(1, 1) = "Report of Complaints"
.Cells(2, 1) = "Date : " & Format(date1.Value, "dd/MMM/yyyy") & "  To : " & Format(date2.Value, "dd/MMM/yyyy")
.Rows(2).Font.Bold = True
.Rows(2).Font.Size = 12
Else
.Cells(1, 1) = "Report of Complaints Received Till  '" & Now() & "'"
End If
.Rows(1).Font.Bold = True
.Rows(1).Font.Size = 18

.Cells(3, 1) = "Total Number Of Complaints: "
.Rows(3).Font.Bold = True
.Rows(3).Font.Size = 18

.Columns(1).ColumnWidth = 9
.Columns(2).ColumnWidth = 12
.Columns(3).ColumnWidth = 11
.Columns(4).ColumnWidth = 11
.Columns(5).ColumnWidth = 15
.Columns(6).ColumnWidth = 12
.Columns(7).ColumnWidth = 12
.Columns(8).ColumnWidth = 15
.Columns(9).ColumnWidth = 18
.Columns(10).ColumnWidth = 21

.Rows(row).Font.Bold = True
For i = 0 To grid.Rows - 1
For j = 1 To grid.Cols - 1
If j = 2 And i > 0 Then
.Cells(row, j).Select
 xlapp.ActiveSheet.Hyperlinks.Add Anchor:=xlapp.Selection, Address:=mpath & "\Log Files\" & grid.TextMatrix(i, j) & "\Log.doc", TextToDisplay:=grid.TextMatrix(i, j)
Else
.Cells(row, j) = grid.TextMatrix(i, j)
End If
.Rows.Font.Name = "Centaur"
.Rows(row).WrapText = True
Next
row = row + 1
Next
.Cells(3, 1) = .Cells(3, 1) & row - 5

.Rows(4).AutoFilter
.Rows(5).Activate
xlapp.ActiveWindow.FreezePanes = True
.PageSetup.LeftMargin = 1
.PageSetup.RightMargin = 1
.PageSetup.PrintGridlines = True
.PageSetup.Orientation = xlLandscape
.PageSetup.Zoom = 90
.PageSetup.PrintTitleRows = "$4:$4"
.PageSetup.CenterFooter = "&P of &N"

xlapp.Visible = True
End With
End Sub

Not allowed special character in vb.net

Not allowed special character in vb.net

 Private Sub txtto_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtto.KeyPress
        Dim ValidInputChar = "#$%^&*,;()[]+{}:'`<>?|~!\/"
        If ValidInputChar.Contains(e.KeyChar) Then
            e.KeyChar = Nothing
        End If
    End Sub