473,395 Members | 2,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

delete file problem

i try to print image file in a directory using PrintDocument. It will raise
printPage event to draw image to the printer. The file will be deleted
after print and the directory will be checked every second to get new file
inside it.
Where should i do the delete function? The way to print image is get from
msdn. Can tell me where can i refer to other better ways to print the
image file.
Thank you.

Public fileName As String

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
End Sub

Sub printImage(ByVal fileName As String)
Dim pd As New PrintDocument
AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
pd.Print()
End Sub

Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As
PrintPageEventArgs)
' Draw a picture.
ev.Graphics.DrawImage(Image.FromFile(fileName),
ev.Graphics.VisibleClipBounds)
' Indicate that this is the last page to print.
ev.HasMorePages = False
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Dim dir As New DirectoryInfo("c:\dir")
Dim fi As FileInfo() = dir.GetFiles()
Dim fitemp As FileInfo

For Each fitemp In fi
fileName = fitemp.FullName
printImage(fileName)
Next
End Sub

___
Newsgroups brought to you courtesy of www.dotnetjohn.com
Nov 21 '05 #1
1 1686
Sorry dude,

can't help much with the printing image side of things, but I hope this is a
HUGE help to you. Instead of using a timer that checks every second, use the
filesystemwatch component. IT ROCKS.

It allows you to select a folder (including sub folders) and watch it and
raise events based on whats going on.

I have attached a small demo project, just add a form (leave it named as
Form1) then go into the code and replace all code with what is below, Run
(F5) then create a txt file in c:\, then open it and change it, rename it
and delete it, it will raise the 4 different events in the filewatch
compoment. It is a cool tool! :)

Regards,

Michael Proctor
Public Class Form1

Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents fsWatch As System.IO.FileSystemWatcher

Friend WithEvents Label1 As System.Windows.Forms.Label

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.fsWatch = New System.IO.FileSystemWatcher

Me.Label1 = New System.Windows.Forms.Label

CType(Me.fsWatch, System.ComponentModel.ISupportInitialize).BeginIni t()

Me.SuspendLayout()

'

'fsWatch

'

Me.fsWatch.EnableRaisingEvents = True

Me.fsWatch.Path = "c:\test\"

Me.fsWatch.SynchronizingObject = Me

'

'Label1

'

Me.Label1.Location = New System.Drawing.Point(176, 56)

Me.Label1.Name = "Label1"

Me.Label1.TabIndex = 0

Me.Label1.Text = "Label1"

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(292, 273)

Me.Controls.Add(Me.Label1)

Me.Name = "Form1"

Me.Text = "Form1"

CType(Me.fsWatch, System.ComponentModel.ISupportInitialize).EndInit( )

Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

fsWatch.Filter = "*.txt"

fsWatch.Path = "c:\"

fsWatch.EnableRaisingEvents = True

End Sub

Private Sub fsWatch_Changed(ByVal sender As System.Object, ByVal e As
System.IO.FileSystemEventArgs) Handles fsWatch.Changed

MsgBox("File: " & e.Name & ControlChars.CrLf & "Path: " & e.FullPath &
ControlChars.CrLf & ControlChars.CrLf & "Was Changed :|")

End Sub

Private Sub fsWatch_Created(ByVal sender As Object, ByVal e As
System.IO.FileSystemEventArgs) Handles fsWatch.Created

MsgBox("File: " & e.Name & ControlChars.CrLf & "Path: " & e.FullPath &
ControlChars.CrLf & ControlChars.CrLf & "Was Created :)")

End Sub

Private Sub fsWatch_Deleted(ByVal sender As Object, ByVal e As
System.IO.FileSystemEventArgs) Handles fsWatch.Deleted

MsgBox("File: " & e.Name & ControlChars.CrLf & "Path: " & e.FullPath &
ControlChars.CrLf & ControlChars.CrLf & "Was Deleted :(")

End Sub

Private Sub fsWatch_Renamed(ByVal sender As Object, ByVal e As
System.IO.RenamedEventArgs) Handles fsWatch.Renamed

MsgBox("File: " & e.Name & ControlChars.CrLf & "Path: " & e.FullPath &
ControlChars.CrLf & ControlChars.CrLf & "Was Renamed >:-|")

End Sub

Private Sub fsWatch_Error(ByVal sender As Object, ByVal e As
System.IO.ErrorEventArgs) Handles fsWatch.Error

MsgBox("Error: " & e.GetException.Message & " in source: " &
e.GetException.Source)

End Sub

End Class

"apple" <ap*******@hotmail.com> wrote in message
news:uj**************@tk2msftngp13.phx.gbl...
i try to print image file in a directory using PrintDocument. It will raise
printPage event to draw image to the printer. The file will be deleted
after print and the directory will be checked every second to get new file
inside it.
Where should i do the delete function? The way to print image is get from
msdn. Can tell me where can i refer to other better ways to print the
image file.
Thank you.

Public fileName As String

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
End Sub

Sub printImage(ByVal fileName As String)
Dim pd As New PrintDocument
AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
pd.Print()
End Sub

Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As
PrintPageEventArgs)
' Draw a picture.
ev.Graphics.DrawImage(Image.FromFile(fileName),
ev.Graphics.VisibleClipBounds)
' Indicate that this is the last page to print.
ev.HasMorePages = False
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Dim dir As New DirectoryInfo("c:\dir")
Dim fi As FileInfo() = dir.GetFiles()
Dim fitemp As FileInfo

For Each fitemp In fi
fileName = fitemp.FullName
printImage(fileName)
Next
End Sub

___
Newsgroups brought to you courtesy of www.dotnetjohn.com

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jobs | last post by:
Hello All, I want to delete all files in a directory. I am making a backup copy of all files in the directories say c:\abc by reading and writing to a file. After making a backup copy I want to...
0
by: Silvia | last post by:
Hi, I have a program that capture images and put this into a listview (using imagelist), the problem is when I delete de image the listview, when do that and capture another image, the image...
23
by: da Vinci | last post by:
Greetings, Onwards with the school studying. Working on a program and need to delete a file from a known location on the hard drive but cannot get anything I do to work. I have tried to use...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
8
by: Richard Arthur | last post by:
This is a weird problem. 1) I use MediaDet to save a bitmap in a temporary file. 2) I create a bitmap using that temporary file's name. 3) I use the bitmap. 4) I want to destroy the file when...
3
by: John Rivers | last post by:
Hello, I think this will apply to alot of web applications: users want the ability to delete a record in table x this record is related to records in other tables and those to others in...
0
by: Silvia | last post by:
Hi, I have a program that capture images and put this into a listview (using imagelist), the problem is when I delete de image the listview, when do that and capture another image, the image...
12
by: Lucas Tam | last post by:
I have a very simple loop: If (Directory.Exists(tempDirectory)) Then Try Dim Files() As String = Directory.GetFiles(tempDirectory) 'Clear out directory For Each Filename As String In Files...
5
by: wo20051223 | last post by:
Deleting some files with C# fails with "Access to the path 'X' is denied". I have files copied from a CD that I burned (and not locked by a process) and a text file that I created in Windows...
3
by: Arpan | last post by:
A Form has a FileUpload, 2 Buttons & a TextBox web server controls. Using the FileUpload control, I want to give users the provision to move & delete files that DO NOT exist in C:\Inetpub\wwwroot...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.