Thursday, March 19, 2009

How to delete files and folder from network drive

Hi, In this sample I will show you how to delete files and folder from your hard drive using VB.NET code.

Let me first explain in words how this will work

DELETE FILES

1. I will get all see if direcoty exists
2. I will delete all files inside "AdnanKhan" directory

Dim sPathTok As String
sPathTok = My.Settings.FilePathName
If IO.Directory.Exists(sPathTok) Then
Dim dir As DirectoryInfo = New DirectoryInfo(sPathTok)
Dim files As FileInfo() = dir.GetFiles
For Each f As FileInfo In files
If f.Name.StartsWith("AdnanKhan") Then
f.Delete()
End If
Next

myLog.WriteLog("Processed: Deleted")

Else
myLog.WriteLog("Processed: Directory Does Not Exists")
End If


'Delete all Directories
Dim sPathDir As String
sPathDir = My.Settings.FilePathNameDir
If IO.Directory.Exists(sPathDir) Then
Dim dir As DirectoryInfo = New DirectoryInfo(sPathDir)
Dim dirs As DirectoryInfo() = dir.GetDirectories
For Each d As DirectoryInfo In dirs
If d.Name.StartsWith("AK") Then
d.Delete(True)
End If
Next
myLog.WriteLog("Process #1: Directories Deleted")
Else
myLog.WriteLog("Process #1: Directory Does Not Exists")
End If

Thank You

Tuesday, March 17, 2009

Wednesday, March 4, 2009

How to make Connection to Oracle from VB.NET

How to connect to Oracle Database using VB.NET

1. You can make a variable into your My Project > Settings
call this variable : sConnectionString
and in value connection string as shown below.

Source=(DESCRIPTION=(ADDRESS_
LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=servername.mycompany.com)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=dev.mycompany.com)));

Note: please make sure you put your servers information in : Host and Service_Name

Now go to the windows form or asp.net page:

Imports this into your page:

Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types

Note: if you can't find this in you project then you download this from oracel website :
Oracle Dll: Oracle.DataAccess.dll
version: 2.102.2.20

Declare Private Variable in your Form1.VB Page:

Private Shared sConnectionString As String = My.Settings.OracleConnectionString

Here is the function:
Public Function ProcessErrorFixDataCheck(ByVal itemNum As String) As Boolean
Dim sqlStr As String
Dim cmd As New Oracle.DataAccess.Client.
OracleCommand
Dim oraDa As OracleDataAdapter
Dim conn As OracleConnection = Nothing
Dim ds As Data.DataSet
Try

sqlStr = "select item_Num from itemTable where item_Num = '" & itemNum & "'"

' Initialize connection
oraDa = New OracleDataAdapter(sqlStr, sConnectionString)
conn = oraDa.SelectCommand.Connection
ds = New Data.DataSet()
oraDa.Fill(ds, "ItemCount")


If ds.Tables(0).Rows(0)(0) IsNot Nothing Then
Return True
Else
Return False
End If

Catch ex As Exception
Throw ex
Finally
cmd.Dispose()
conn.Close()
conn.Dispose()
GC.Collect()
End Try
End Function

Wednesday, February 18, 2009

VB.NET - How to print graphics from windows form

Here how you will print image from your windows application

step 1:
Imports System.Drawing.Printing
Imports System.Drawing.Imaging

step2:
Drag and drop PrintDocument Control on your windows form and rename control name to: PrintGraphicControl

step3:
Put this in your code

Dim GraphicLocation as TextBox = New TextBox()
GraphicLocation.Text = "c:\myimage.jpg"
AddHandler PrintGraphicControl.PrintPage, AddressOf Me.GraphicPrint
PrintGraphicControl.Print()

#Region "Print Graphics"
Private Sub GraphicPrint(ByVal sender As Object, ByVal e As PrintPageEventArgs)
e.Graphics.DrawImage(Image.FromFile(GraphicLocation.Text), e.Graphics.VisibleClipBounds)
e.HasMorePages = False
End Sub
#End Region

Tuesday, February 17, 2009

LendMySpace.Com is just launched




LendMySpace.Com is just launched.

About LendMySpace

LendMySpace.Com is online media ad service to all of ours users who would like to sell their new/old item(s) or services online through our website. We make every effort to make buying and selling more interactive by providing a forum where the buyer and seller can easily contact each other. We strive to do this through advanced technology, in-depth research and above all the highest quality of customer service delivered with a sense of warmth, understanding, respect, and company spirit.

So please take sometime to visit us at: http://www.lendmyspace.com