Wednesday, 24 July 2013

Conversion Of .rft, .txt And .doc File In To .pdf File In Vb.net


I write the program for conversion of .txt and .rtf in to the .pdf files. for this  program we
need to create a function  of conversion. Otherwise we need to use third party utility and
call the function from it,in our program.
                                                 Here i do the same ,i use third party utility in my program.
My project is in VS 2010 window form.let's see the program step by step ,what i do:-
1)Create your own functions(.dll) or download third party dll. and locate in  your system folder
    C:\Windows\System32.
2)Open your project and right click on project and click on 'Add Reference' form 'Browse' 
    tab in new dialog box select that(downloaded dll).
3)Drop the one button in your window form,write the code in Click_event.
4)Import that  dll in porgram and write the below code:-
5)In this program 'SautinSoft.PdfMetamorphosis' is the third party dll and 'RtfToPdfConvertFile'
   function.

Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.IO
Imports System.Windows.Forms.Form

Public Class Form1
    
    Private Sub _Open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
                                                                                                           Handles _Open.Click
        InitializeComponent()
        Dim openFile As New OpenFileDialog
        Dim p As New SautinSoft.PdfMetamorphosis()
        openFile.Filter = "All Files (*.*)|*.*"
        openFile.ShowDialog()
        p.PageStyle.PageOrientation.Landscape()

        'specify header in HTML format
        p.Header.Html("<b>Sample header in HTML format</b>")

        'specify footer in RTF format
        p.Footer.Rtf("{\b Bold footer}")

        'specify page numbers
        p.PageStyle.PageNumFormat = "Page {page} of {numpages}"

        If p IsNot Nothing Then
            Try
                'Dim str As String
                TextBox1.Text = openFile.FileName
                Dim rtfPath As String = TextBox1.Text
                Dim pdfPath As String = "D:\test.pdf"
                Dim pdfPath1 As String = "D:\test1.pdf"
                p.RtfToPdfConvertStringToFile("hello shiv", pdfPath1)
                Dim i As Integer = p.RtfToPdfConvertFile(rtfPath, pdfPath)

                If i = 0 Then
                    System.Diagnostics.Process.Start(pdfPath)
                Else
                    MessageBox.Show("An error occured during converting RTF to PDF!")
                End If
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End If
    End Sub   
End Class

Wednesday, 17 July 2013

How To Access Web Services From Service Reference In Vb.net

Access WebServices  In Vb.net

Here i describe about the web service access from vb.net, some time our requirement data 
is depend upon in web service,Then  we get the data from available function of web service.
I write here steps of access the web services:-
1)Open the 'VS 2010' ,create a new project of  'Excel Addins 2010' .
2)Add  a Ribbon and Button , Write a code on Click_Event.
3)Before the writing  ,we need to add 'service reference' ,for exanple.
   Here i create a project named 'BvdDataAddIn'.
4)Right click on project select  "Add Service Reference" ,open a new window 
  asking for Url , you just feed  the url address  of web services and give it's 
  (like i give 'BvdServiceReference').  click 'Ok' button.
5)After add 'Web Reference' ,double click on 'FindByBvdID' button. 
6)Here I write the code  according my 'Web Reference'(You can change it).

Imports Microsoft.Office.Tools.Ribbon
Imports System
Imports System.Runtime.InteropServices
Imports System.ComponentModel
Imports System.Windows.Forms
'Imports AddinExpress.MSO
Imports Excel = Microsoft.Office.Interop.Excel
Imports System.Data
Imports System.IO
Imports System.Diagnostics
Imports BvdDataAddIn.BvdServiceReference

Public Class BvdID
    Dim activesheet As Excel.Worksheet
    Dim range As Excel.Range

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As       
                              Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs)  Handles Button1.Click
        Try
            Dim service As New RemoteAccessSoapClient()
            Dim selectionResult As BvdServiceReference.SelectionResult
            Dim sessionHandle As String
            Dim bvddata As New BvdDataAddIn.BvdID
            Dim row As Integer
            Dim bvdId As String
            Dim data As String
            Dim dataSet As New System.Data.DataSet
            Dim dataTable As DataTable

            sessionHandle = service.Open("ijameel", "Pwcwelcome1")
            activesheet = Globals.ThisAddIn.Application.ActiveSheet
            'Lastrow = activesheet.Cells.Find("*", SearchOrder:=Excel.XlSearchOrder.xlByRows,  
                                 SearchDirection:=Excel.XlSearchDirection.xlPrevious).Row
            For row = 2 To 2
                'range = activesheet.Cells("A" & row, 1)

                'If range.Value = vbNull Then
                'End If
                bvdId = "BE0878480104"

                'Try
                '    bvdId = range.Value.ToString()
                'Catch ex As Exception
                '    MsgBox(ex.ToString)
                'End Try

                'Marshal.ReleaseComObject(range)
                If (String.IsNullOrEmpty(bvdId)) Then
                End If

                selectionResult = service.FindByBVDId(sessionHandle, bvdId)
                If selectionResult.SelectionCount <> 0 Then
                    data = service.GetData(sessionHandle, selectionResult, "SELECT 
                                NAME,ADDR,ADDR2,ADDR3,CITY,POSTCODE,STATE,COUNTY,
                                 COUNTRY,WEBSITE FROM RemoteAccess.A", 0, 1,
                                 BvdServiceReference.ResultFormatting.MSDataS et)
                    dataSet.ReadXml(New StringReader(data))
                    dataTable = dataSet.Tables(0)
                    activesheet.Cells(row, 2).Value = dataTable.Rows(0).Item(0)
                    activesheet.Cells(row, 3).Value = dataTable.Rows(0).Item(1)
                    activesheet.Cells(row, 4).Value = dataTable.Rows(0).Item(2)
                    activesheet.Cells(row, 5).Value = dataTable.Rows(0).Item(3)
                    activesheet.Cells(row, 6).Value = dataTable.Rows(0).Item(4)
                    activesheet.Cells(row, 7).Value = dataTable.Rows(0).Item(6)
                    activesheet.Cells(row, 8).Value = dataTable.Rows(0).Item(7)
                    activesheet.Cells(row, 9).Value = dataTable.Rows(0).Item(8)
                    activesheet.Cells(row, 10).Value = dataTable.Rows(0).Item(9)
                End If
            Next
            service.Close(sessionHandle)

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class

7)Run the program and click on 'FindByBvdID' ,your data will display on worksheet.