|
First, scrap this service. If you can't write the code to search for files in a normal app, writing it as serice will only serve to frustrate you to death. Besides, the way you've written this code demonstrates a lack of understanding how Services work, how to write them, and most importantly, how to communicate with them to get them to do something useful.
The Timer isn't doing anything other than creating an event log on every tick of the timer.
You have no method of calling your function. Sure, it CAN work as a search, but you have no methods in here that allow for communication with the service in any way, so you have no way to call the search code.
Services require you to do a lot more planning up front. There's no such thing a "whipping one togther" like you can with a Console or Windows Forms app.
There's nothing in this code to salvage to get a working service. This thing really does need to be scrapped.
Simplify your code and get a working search in a Console or Windows Forms app first. The experience you get with that will show you what a search needs for input and what it can return as output and how it needs to be returned. After that, you can add threading support, which will give you the basis for writing a service that's going to work. You can't do this with a Timer...
|
|
|
|
|
I have started working on a search in a windows forms app but when I try to run the program I get the following security Exception
"Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."
Here is my code:
Dim FilePath As String = TextBox1.Text
Dim FileType As String = TextBox2.Text
Dim diContents As New DirectoryInfo(FilePath)
Dim di As FileInfo
Dim filename As String = ListBox1.SelectedIndex
Dim testname As String
For Each di In diContents.GetFiles
Dim dirs() As String = Directory.GetFiles(FilePath & di.Name)
For Each filename In dirs
testname = System.IO.Path.GetFileName(filename)
Dim fileTest As String = testname.Remove(0, (Len(testname) - 3))
If UCase(fileTest) = FileType Then
ListBox1.Items.Add(testname)
End If
Next
Next
End Sub
Just to explain what I am trying to do, I want to enter the file path into the textbox where I want to search for the files. I want to enter the file extension(.txt, .mp3) into a textbox to specific what type of file I am looking for. Once the files are found, add them to the list box on the form. Is this code correct?
This line of code(Dim diContents As New DirectoryInfo(FilePath)) is highlighted when error occurs.
Any ideas?
jds1207
|
|
|
|
|
Nowhere in your code is there any provisions for handling the inevitable "access denied" error. Your code probably bombed in the root of your C: drive on a folder called "System Volume Information". You have to put some of this code in Try/Catch blocks to handle this eventuallity and deal with it as you must.
|
|
|
|
|
Don't tell me, tell the OP. That way, he'll get the email notification that you replied, not me.
|
|
|
|
|
sorry Dave,
i thought every one involved with a thread will get a notification when new post created
Vilsad P P
MCTS (Windows Applications) .Net 2.0
|
|
|
|
|
i didn't see any output from your search, just calling di.listfiles(type) but not adding it to anywhere!
and you are searching only C drive, what if your computer have morethan one drive.
try this
initialise your search like this
dim drv as driveinfo<br />
for each drv in my.computer.filesystem.drives()<br />
if drv.isready then<br />
searchfiles(drv.rootdirectory,type)<br />
end if<br />
next
and create a searchfiles method with path and filetype as parameters
private sub searchfiles(byval path as directoryinfo,byval filetype as string)<br />
try<br />
'this will handle the error access denied<br />
'list files<br />
dim fi as fileinfo<br />
for each fi in di.getfiles(filetype)<br />
Application.DoEvents()<br />
'do something with the file here<br />
next<br />
'now go through the directories and get files from subdirectories<br />
dim sdi as directoryinfo<br />
for each sdi in di.getDirectories()<br />
Application.DoEvents()<br />
searchfiles(sdi,filetype)<br />
next <br />
catch exception as ex<br />
end catch<br />
end sub
this will get you through all the directories in a computer.
hope this works for you
Vilsad P P
MCTS (Windows Applications) .Net 2.0
|
|
|
|
|
Hello there..
Iam doing an application, studio 2003, vb.net, and what i need is:
1: I want this application to start up when windows starts (turn on the pc).
2: When i hit the close button, (up right of the window), the application to be minimized at the taskbar, near the clock icon, like msn and yahoo messenger is.
Very thanksfull....
Scorpion.
|
|
|
|
|
scorp_scorp wrote: I want this application to start up when windows starts (turn on the pc).
This article might help.
scorp_scorp wrote: When i hit the close button, (up right of the window), the application to be minimized at the taskbar
Check out the NotifyIcon.
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
1) place a shortcut to your app in the start menu/programs/startup folder
2) do research on System.Windows.Forms.NotifyIcon
in the forms' closing event
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
e.cancel=true
me.hide
turn on the notifyicon object
End Sub
|
|
|
|
|
Hi
How can I display row numbers on the left hand side of a datagridview control. (i.e. not in the cells)
|
|
|
|
|
hi RichardBerry,
try following code
Dim i As Integer
For i = 0 To datagridview1.Rows.Count - 1
datagridview1.Rows(i).HeaderCell.Value = CStr(datagridview1.Rows(i).HeaderCell.RowIndex + 1)
Next
hope this helps
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
|
|
|
|
|
Hi Rupesh
Thanks, that does work
I was however hoping for somthing automatic. Also if I delete a row, then I will have to catch that event and renumber the rows.
Thanks for your help though
|
|
|
|
|
|
Hi,
I have a need to send some data from database to a word template.
Do any body have any idea about it.
Example: If i have a word file as certificate.doc (with images and text)
and at particular occurance of word as <name> the text has to change with database field.
Any help... plz
Jats
|
|
|
|
|
Hi ,
I want to update my database with the names and contact info of the ppl by using the Whitepages.com site from the reverse numbers option. I m using httpWebrequest and httpWebresponse classes to work it out .. but i m unable to get the page with the desired data ( same as when a user types a number s and presses search button). I have used the POST method and appended the post data but the same default page is returned to me . can any body help me out ???
|
|
|
|
|
hi all,
I dynamically create buttons on main_form, then in a module (functions) i try to access this controls by setting an focus to one of them.
when i try to access with "index = Frm_Main.CtrlFocus" it doesnt work becouse number of controls is zero since this frm_main is new instance i guess?!
Does anyone know how to fix this, and if there is a better way?
Thanks
greg
Public Class Frm_Main
Dim WithEvents BtnOperate As New OpenNETCF.Windows.Forms.Button2
Private Sub Frm_Main_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.BtnOperate.Location = New System.Drawing.Point(20, 20)
Me.BtnOperate.Size = New System.Drawing.Size(150, 150)
Me.BtnOperate.TabIndex = 0
Me.Controls.Add(Me.BtnOperate)
Me.BtnOperate.BackgroundImage = b
Me.BtnTest2.Location = New System.Drawing.Point(340, 20)
Me.BtnTest2.Size = New System.Drawing.Size(150, 150)
Me.BtnTest2.TabIndex = 2
Me.Controls.Add(Me.BtnTest2)
Me.BtnTest2.BackgroundImage = b
End Sub
Public Property CtrlFocus() As Integer
Get
Dim i As Integer = Me.Controls.Count
Dim ctrl As Control
For Each ctrl In Me.Controls
If ctrl.Focused Then
Return ctrl.TabIndex
End If
Next
End Get
Set(ByVal value As Integer)
Dim ctrl As Control
For Each ctrl In Me.Controls
If ctrl.TabIndex = value Then
ctrl.Focus()
End If
Next
End Set
End Property
End Class
Public Class Functions
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SP1.DataReceived
BytesToRead = SP1.BytesToRead
Dim buffer(BytesToRead - 1) As Byte
SP1.Read(buffer, 0, BytesToRead)
message = message + System.Text.Encoding.Default.GetString(buffer, 0, BytesToRead)
SP1.DiscardInBuffer()
If message.IndexOf(Chr(3)) > -1 Then
Dim STX As Integer = message.IndexOf(Chr(2))
If message(STX + 1) = "K" Then
Dim index As Integer
Select Case message(STX + 2)
Case "U"
index = Frm_Main.CtrlFocus
index = (index + 4) Mod 8
Frm_Main.CtrlFocus = index
End Select
End If
End Sub
|
|
|
|
|
Stop spamming the forums!
-- modified at 10:52 Tuesday 8th May, 2007
This was originally a response to a message that has since been deleted.
|
|
|
|
|
I have created one application in VB.Net.
I want to create one shortcut for it
like Window key+E (for Explorer).
How can i do that?
|
|
|
|
|
I'll need some clarification.
Are you looking for a shortcut like from you own desktop or are you looking for how to create a shortcut to your application from within a distribution set? So as to automatically create a shortcut on a users PC desktop when installing your app.
Jelle
|
|
|
|
|
automatically create a shortcut on a users PC desktop when installing app.
|
|
|
|
|
You will need to use Win32 API.
here are functions you can use...
<br />
[DllImport("USER32.dll")]<br />
public static extern bool RegisterHotKey(IntPtr hWnd,<br />
int id, int fsModifiers, int vlc);<br />
<br />
[DllImport("USER32.dll")]<br />
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);<br />
"If our Mind can, the Program can !!"
|
|
|
|
|
Are you going to check whether the user is using that shortcut for something else first? Hijacking users' control over their own machines is not a way to create good will towards your app.
|
|
|
|
|
i have a datagridview and two table of record, one is parent and another is child table.
so, how can i binding the record to the datagrid so the data can nested?
Regards,
Chee ken
|
|
|
|
|
Hi,
Currently I am designing a tool in VB.Net for automation of a datawarehousing tool called DataStage. I have to run this tool through command prompt in VB.Net. The command is
dsjobs –server xx.xxx.xx.xx –user abcd –password wxyz –run
[Project] [Job] [List of parameters]
Application path is the location where datastage client is installed in the local machine.
Other attributes like:
-lparam: Give the list of parameters for a particular job
-ljobs: List all the jobs in a particular project
-lprojects: List all the projects available in the server
-run: To run a job
-stop: To stop a job etc….
Now can anyone help me how to put these in VB.Net and how to fetch the results of these commands. Because based on the results of these commands I have to create dynamic text boxes.
It looks complicated, but can anyone who knows this help me out ?
Thanks in advance.
-- modified at 4:37 Tuesday 8th May, 2007
|
|
|
|
|
Process.Start is basically shellexecute, you can pass your parameters through there.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|