Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unique File Names, toUpper() ? 1

Status
Not open for further replies.

Gatchaman

Programmer
Jan 21, 2003
71
0
0
AU
Hey all, I have a dilemma.

I have a system the uses XML files, but, of course, no two files can have the same name. Firstly, each 'case' is given a name when it is submitted and put into a database, at this point, I don't want any cases to be submitted that have the same name as either an existing record, or an existing XML file. Once a case is 'selected' from the database to be made into a new XML file, it is removed from the database, however, during this procedure, you can choose to rename the case. At this point I don't want the case to be able to be renamed to that of another case in the database or an existing XML file. Does that make sense ?

So, I set up the validation and it worked fine with my un-imaginative test cases. Then, I got a case name wrong by not capitalising the first letter, which didn't tell me that a record/file already existed of that name, and instead proceded to try and make a new XML file 'john.xml' when there already existed a 'John.xml', which gave an error.

So, what I've guessed that I have to do is use something like toUpper, if such a thing exists, to do comparisons so that John will look like john in a string comparison. Any help would be appreciated, I've included an example of one of the parts where I check :


Dim matchFound
matchFound = False

Dim DB
Set DB = Server.CreateObject("ADODB.Connection")
DB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/windows/login/possumweb.mdb")
DB.Open

Dim RS
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open "SELECT * FROM SubmittedCases WHERE CaseName = '" & Request.Form("txtCaseName") & "' AND Submitted = FALSE", DB

If RS.EOF = False AND RS.BOF = False Then
matchFound = True
End If

RS.Close
Set RS = Nothing

DB.Close
Set DB = Nothing

If matchFound = False Then
Dim fSystem, fObject, f, fileName
fileName = Request.Form("txtCaseName") & ".xml"
Set fSystem = Server.CreateObject("Scripting.FileSystemObject")
Set fObject = fSystem.GetFolder(Server.MapPath("/windows/user/forum/bin/case/"))

For Each f In fObject.Files
If f.Name = fileName Then
matchFound = True
End If
Next

If matchFound = False Then
Set fObject = fSystem.GetFolder(Server.MapPath("/windows/user/forum/bin/case/archive/"))

For Each f In fObject.Files
If f.Name = fileName Then
matchFound = True
End If
Next
End If

Set fObject = Nothing
Set fSystem = Nothing
End If


Thanks in advance,

Damon
 
Doh, I use fSystem.FileExists in so many other places I don't know why I didn't think of it :(

A star for you for the UCase too, I'll still need to use that. Thanks :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top