Sunday, September 14, 2008

Using Generic lists with crystal reports in .net

Public Sub ReportDocumentListDetails(ByVal rptPath As String, ByVal reportname As String, ByVal rptdoc As CrystalDecisions.CrystalReports.Engine.ReportDocument, _

ByVal arListName As System.Collections.ArrayList, ByVal arListValue As System.Collections.ArrayList)

Dim rptViewer As New CrystalDecisions.Windows.Forms.CrystalReportViewer()

Dim ds As DatasetReport = New DatasetReport

If (arListName.Count = arListValue.Count) Then

For i As Integer = 0 To arListName.Count - 1

rptdoc.SetParameterValue(arListName(i).ToString, arListValue(i))

Next

End If

Dim objExOpt As CrystalDecisions.Shared.ExportOptions

Dim objDiskOpt As New CrystalDecisions.Shared.DiskFileDestinationOptions

objDiskOpt.DiskFileName = "F:\nath\" & reportname & ".pdf"

objExOpt = rptdoc.ExportOptions

objExOpt.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile

objExOpt.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat

objExOpt.DestinationOptions = objDiskOpt

rptdoc.Export(objExOpt)

rptdoc.Close()

End Sub

Export options of crystal reports and passing parameters to crystal reports in .net

Public Sub ReportDocumentDetails(ByVal rptPath As String, ByVal reportname As String, ByVal dtReport As DataTable, _

ByVal arListName As System.Collections.ArrayList, ByVal arListValue As System.Collections.ArrayList)

Dim rptViewer As New CrystalDecisions.Windows.Forms.CrystalReportViewer()

Dim ds As DatasetReport = New DatasetReport

Dim rptdoc As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument

rptdoc.Load(rptPath)

rptdoc.SetDataSource(CType(dtReport, DataTable))

If (arListName.Count = arListValue.Count) Then

For i As Integer = 0 To arListName.Count - 1

rptdoc.SetParameterValue(arListName(i).ToString, arListValue(i))

Next

End If

Dim objExOpt As CrystalDecisions.Shared.ExportOptions

Dim objDiskOpt As New CrystalDecisions.Shared.DiskFileDestinationOptions

objDiskOpt.DiskFileName = "F:\nath\" & reportname & ".pdf"

objExOpt = rptdoc.ExportOptions

objExOpt.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile

objExOpt.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat

objExOpt.DestinationOptions = objDiskOpt

rptdoc.Export(objExOpt)

rptdoc.Close()

End Sub

Monday, September 8, 2008

Working with Attachments in Outlook Email using .net 2.0

Dim olApp As Microsoft.Office.Interop.Outlook.Application = New ApplicationClass()
Dim oNameSpace As Microsoft.Office.Interop.Outlook.NameSpace = olApp.GetNamespace("MAPI")
Dim oOutL As New Outlook.Application
Dim oMail As Outlook.MailItem

Dim objFolder As MAPIFolder = oNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderInbox)
Dim oItems As Items = objFolder.Items

Dim twmp As Integer = 15
Do While (twmp >= 0)
oMail = CType(objFolder.Items((objFolder.Items.Count - twmp)), MailItem)
If (oMail.UnRead = True) Then
If (oMail.Subject = "Document") Then
oMail.Attachments(1).SaveAsFile("E:\VBABonds\kaushik\" & oMail.Attachments(1).FileName)
End If
End If
twmp = (twmp - 1)
Loop

Friday, September 5, 2008

Open word file using vb.net 2,0 in windows application

To open ms word file using vb.net 2.0 in windows application

Add reference microsoft.word 12.o object from com tab.

If (System.IO.File.Exists(txtBrowse.Text)) Then

Dim test As Microsoft.Office.Interop.Word.Application

test = New Microsoft.Office.Interop.Word.Application

test.Documents.Open(txtBrowse.Text)

test.OpenAttachmentsInFullScreen = True

test.Visible = True

End If

Thursday, September 4, 2008

Storing and Downloading ms word file in ms access file using VB.NET 2.0

Storing a ms word file in access database using VB.NET 2.0


Dim objcon As System.Data.OleDb.OleDbConnection = CommonFunctions.clsCommonFunctions.OleDbConnections()

Dim objcmd As System.Data.OleDb.OleDbCommand = New OleDb.OleDbCommand("", objcon)

Dim par As OleDb.OleDbParameter = New OleDb.OleDbParameter("@Attachment", OleDb.OleDbType.LongVarBinary)

Dim strText As String = "update bonds set Attachment=@Attachment where bondsid=" & txtDBaseRefNo.Text

objcon.Open()

Dim fs As New System.IO.FileStream _

(TextBox1.Text, System.IO.FileMode.OpenOrCreate, _

System.IO.FileAccess.Read)

Dim MyData(fs.Length) As Byte

fs.Read(MyData, 0, fs.Length)

fs.Close()

par.Value = MyData

objcmd.CommandText = strText

objcmd.Parameters.Add(par)

Dim i As Integer = objcmd.ExecuteNonQuery()

fs = Nothing

objcon.Close()


Downloading ms word file from ms access database using VB.NET 2.0


Dim objcon As System.Data.OleDb.OleDbConnection = CommonFunctions.clsCommonFunctions.OleDbConnections()

Dim command As System.Data.OleDb.OleDbCommand = New System.Data.OleDb.OleDbCommand( _

"select Attachment from bonds where bondsid=" & txtDBaseRefNo.Text, objcon)

' Writes the BLOB to a file (*.bmp).

Dim stream As System.IO.FileStream

' Streams the binary data to the FileStream object.

Dim writer As System.IO.BinaryWriter

' The size of the BLOB buffer.

Dim bufferSize As Integer = 100

' The BLOB byte() buffer to be filled by GetBytes.

Dim outByte(bufferSize - 1) As Byte

' The bytes returned from GetBytes.

Dim retval As Long

' The starting position in the BLOB output.

Dim startIndex As Long = 0

' The publisher id to use in the file name.

Dim pubID As String = ""

' Open the connection and read data into the DataReader.

objcon.Open()

Dim reader As System.Data.OleDb.OleDbDataReader = command.ExecuteReader(CommandBehavior.SequentialAccess)

Do While reader.Read()

' Get the publisher id, which must occur before getting the logo.

'pubID = reader.GetString(0)

' Create a file to hold the output.

stream = New System.IO.FileStream( _

"C:\Documents and Settings\Gopinath\Desktop\doccc1111.doc", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write)

writer = New System.IO.BinaryWriter(stream)

' Reset the starting byte for a new BLOB.

startIndex = 0

' Read bytes into outByte() and retain the number of bytes returned.

retval = reader.GetBytes(0, startIndex, outByte, 0, bufferSize)

' Continue while there are bytes beyond the size of the buffer.

Do While retval = bufferSize

writer.Write(outByte)

writer.Flush()

' Reposition start index to end of the last buffer and fill buffer.

startIndex += bufferSize

retval = reader.GetBytes(0, startIndex, outByte, 0, bufferSize)

Loop

' Write the remaining buffer.

writer.Write(outByte, 0, retval - 1)

writer.Flush()

' Close the output file.

writer.Close()

stream.Close()

Loop

' Close the reader and the connection.

reader.Close()

objcon.Close()




Tuesday, September 2, 2008

Run Executable file in ASP.NET

i will provide a code snippet of how to run a process (in this case it is WindowsMediaPlayer.exe) which exists in your application root folder.

// Create An instance of the Process class responsible for starting the newly process.

System.Diagnostics.Process process1 = new System.Diagnostics.Process();

// Set the directory where the file resides

process1.StartInfo.WorkingDirectory = Request.MapPath("~/");

// Set the filename name of the file you want to open

process1.StartInfo.FileName = Request.MapPath("WindowsMediaPlayer.exe");

// Start the process

process1.Start();


Run a .EXE from a VB.NET application?

To run a .EXE file from a VB.NET application you need to import the System.Diagnostics namespace. The following sample shows how to run Notepad from a VB.NET application.

Imports System
Imports System.Diagnostics
Dim program As New Process()
program.StartInfo.FileName = "Notepad.exe"
program.StartInfo.Arguments = " "
program.Start()