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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with CreateTextFile 1

Status
Not open for further replies.

paulparky

Programmer
Oct 10, 2001
29
PA
I have a problem with CreateTextFile in that whenever I try to use a variable in the filename I get the error "bad filename or number".
The code I'm using is

outputfile = "//192.168.10.152/encoded/" & filenumber & ".enc"
Set objfso = Server.CreateObject("Scripting.FileSystemObject").CreateTextFile(outputfile,True)


If I replace "filenumber" with a literal string i.e outputfile = "//192.168.10.152/encoded/testfile.enc" it creates the file without problem, but as I need to use a variable name for the filename,does anyone have any ideas/pointers to resolve this.
 
try:

outputfile = "//192.168.10.152/encoded/"&TRIM(filenumber)& ".enc"

-DNG
 
Are you certain that the value of filenumber is what you think it is? Is it a valid file name?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Try using Response.Write(filenumber) to see what value is being used.
 
Hi guys,
DotNetGnat - The Trim(filenumber) gives me the same result "bad filename or number"

TomThumbKP - the filename variable is a string consisting of Alpha and numeric characters upto 13 in length. If I put the same string as a literal the file creates without problem. I have displayed the variable name beforehand and cannot see any characters that would deem the filename invalid.
 
Can you do a Response.Write(outputfile) and paste what you get into this thread?

cheers
 
Either this statement:

"If I put the same string as a literal the file creates without problem."

or this statement:

"I have displayed the variable name beforehand and cannot see any characters that would deem the filename invalid."

Is incorrect. Since concatenating multiple strings results in a string literal.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
the only option left for you to debug this is to use...

Response.Write

-DNG
 
the code outputfile = "//192.168.10.152/encoded/" & fileNumber & ".enc"
response.write(outputfile)
gives the result
//192.168.10.152/encoded/TXLU8393021.enc
but I get the error with this code.
If the code states outputfile = "//192.168.10.152/encoded/TXLU8393021.enc" I get no error and the file creates correctly.
 
try this:

outputfile = """ & "//192.168.10.152/encoded/" & fileNumber & ".enc" &"""

-DNG
 
Look for any nonprintable char in filenumber, if any.
[tt] response.write escape(trim(filenumber))[/tt]
 
Thanks guys. There was actually noprintable characters in there being picked up from the xml data source file. Sorted it now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top