|
Yeah, so long as all you're doing is searching to see if the username exists already, there shouldn't be any issues. That is, of course, unless the Admin's changed the default permissions of the User's doing the searching!
|
|
|
|
|
Ok now Im frustrated
I haver this function to search the AD
Public Shared Function IsValidADLogin(ByVal loginName As String, ByVal givenName As String) As fnStatRtn
Dim oReturn As New fnStatRtn(True)
Dim search As New DirectorySearcher()
Try
search.Filter = String.Format("(&(SAMAccountName={0})(givenName={1}))", loginName, givenName)
search.PropertiesToLoad.Add("cn")
search.PropertiesToLoad.Add("SAMAccountName")
Dim result As SearchResult = search.FindOne()
Dim samaccountname As String = CStr(result.Properties("SAMAccountName")(0))
MsgBox(samaccountname)
If result Is Nothing Then
oReturn.FnCompletedSuccessfully = False
oReturn.colReturnItems.Add("Login Name provided isnt valid. Please try again.")
Else
oReturn.FnCompletedSuccessfully = True
End If
Catch ex As Exception
amaDBHelper.CatchErrors(oReturn, ex, "IsValidADLogin Error")
End Try
Return oReturn
End Function
But when I try to msgbox the value I get a Object reference not set to an instance of an object. error.
"Okay, I give up: which is NOT a real programming language????"
Michael Bergman
"Well yes, it is an Integer, but it's a metrosexual Integer. For all we know, under all that hair gel it could be a Boolean."
Tom Welch
"Let's face it, the average computer user has the brain of a Spider Monkey."
Bill Gates
|
|
|
|
|
|
You're joking, right? Think question isn't answerable.
"Save data" is a very generic term and can mean anything. Saving data to what? A file? What kind of file? A database? A file server? An FTP server? Web server? the Registry??, ... What kind of data?? There's so many ways to persist data in som many places that it's impossible to answer your question.
|
|
|
|
|
a data base of some sort..
sorry im new to these things ! im just starting to learn VB from the net and i almost know nothing.. help will be appreciated
|
|
|
|
|
I highly suggest picking up a book on VB.NET for beginners. If you're that new to this, you really need to learn the basics of OOP and the .NET Framework before you try and tackle a project that deals with a database.
|
|
|
|
|
will do ! thankx for the advice !
|
|
|
|
|
I'm working on a shoppingCart and try to delete multiple rows at once, but get error message:
"Collection was modified; enumeration operation may not execute."
Here is my code:
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
For Each row As GridViewRow In GridView1.Rows
Dim chk As CheckBox = CType(row.FindControl("Remove"), CheckBox)
If Not chk Is Nothing AndAlso chk.Checked Then
Dim ID = New Guid(GridView1.DataKeys(row.RowIndex).Value.ToString())
StoreManager.RemoveItem(ID)
End If
Next
End Sub
Code for:
Class StoreManager
Public Shared Sub RemoveItem(ByVal id As Guid)
ShoppingCart.Remove(id)
End Sub
Code for:
Class ShoppingCart
Public Sub Remove(ByVal id As Guid)
For Each existingProd As OrderedProducts In _items
If id = existingProd.ID Then
_items.Remove(existingProd)
End If
Next 'error calls this line!!!
End Sub
Not sure how to fix error!
|
|
|
|
|
You cannot use For/Each/Next on a collection if you're going to modify the collection. You have to use For/Next with an indexing variable, and you have to iterate over the collection backwards, meaning you start at the end and work your way back to the beginning.
For i As Integer = GridView1.Rows.Length - 1 to 0 Step -1
.
.
Next
|
|
|
|
|
Hmmm, I tried this but still get same error
For i As Integer = GridView1.Rows.Count - 1 To 0 Step -1
Dim row As GridViewRow = GridView1.Rows(i)
Dim chk As CheckBox = CType(row.FindControl("Remove"), CheckBox)
If Not chk Is Nothing AndAlso chk.Checked Then
Dim ID = New Guid(GridView1.DataKeys(row.RowIndex).Value.ToString())
StoreManager.RemoveItem(ID)
End If
Next
|
|
|
|
|
Ok, found the problem and fixed it:
Public Sub Remove(ByVal id As Guid)
For i As Integer = _items.Count - 1 To 0 Step -1
Dim existingProd As OrderedProducts = _items(i)
If id = existingProd.ID Then
MsgBox("Found Product! Count: " & _items.Count.ToString() & "items")
_items.Remove(existingProd)
MsgBox("Deleted Product! Count: " & _items.Count.ToString() & "items")
End If
Next
End Sub
Thanks a lot!!!
|
|
|
|
|
I am trying to write a program that will search the hard drive for files using windows service in vb.net. I already created the service, but I am not sure if my code to search for files is correct. Does anyone have any suggestions or samples on how to search for files using vb.net. Here is the code that I have below:
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
Timer1.Enabled = True
SearchFiles(".txt")
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
Timer1.Enabled = False
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'Check if the event log exists
If Not System.Diagnostics.EventLog.SourceExists("MyService") Then
'Create Log
System.Diagnostics.EventLog.CreateEventSource("MyService", "Myservice Log")
End If
EventLog.Source = "MyService"
'Write to the log
System.Diagnostics.EventLog.WriteEntry("MyService Log", "This is log on " & _
CStr(TimeOfDay), EventLogEntryType.Information)
End Sub
Private Sub SearchFiles(ByVal FileType As String)
Dim FilePath As String = "c:\"
Dim rootDi As New DirectoryInfo(FilePath)
Dim Di As DirectoryInfo
For Each Di In rootDi.GetDirectories
Directory.GetFiles(FilePath, FileType)
Next
End Sub
Please help!
jds1207
|
|
|
|
|
I would just use File.Exists method. Or were you trying to list each file that you searched?
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
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
|
|
|
|