|
|
|
|
|
|
|
Problem of Comma and how can password protect a CSV file?
|
|
|
|
| Subject |
Author |
Status |
Date |
Re: Problem of Comma and how can password protect a CSV file?
|
Henri Teipel |
|
12/20/2007 9:57:20 PM |
I just opened it in excel and didn't see a problem although I could see the commas in notePad. The line 53 is supposed to remove trailing commas. If you haven't altered that line than there shouldn't be a problem. It is possible that excel is adding the commas when it is used to open the file. You could definitely work out a script that searches through the saved lines and removes all fo the trailing commas. Do you need a hint to start that?
C SV files are just plain text files, so there is no built-in way to password-protect them. I d on't think you can specify a user name and password when you work with the fileSystemObjec t. Do you just want extra security? If so, you could put all of these scripts on a folder and restrict access to that folder. When a user tries to go to this folder he should be prompted b y the server to provide a password. Let me know if this helps. Post Comments |
|
Re: Thank you!!!
|
Pullatti Jamaica |
|
12/20/2007 9:58:30 PM |
Henri, Thanks for getting back to me. Yes, I could use any help you have to offer on a script to get rid of the extra commas.
As for security, I am looking into putting the file in a private file on the server. I just need to find out the url of the private directory to put into the form handler. Post Comments |
|
Re: See some of the scripts
|
Henri Teipel |
|
12/20/2007 9:59:47 PM |
You see in some of my scripts above how I open the file and separate each line of the db onto its own line, right? I made this so that the first line is called lines(0), the second is called lines(1) etc. Perhaps after the end of this script you could open the file to read the same as at first. Once you have each line separated you can do this: Code: ( asp ) -
for each x in lines -
do until right(trim(lines(x)),1) <> "," -
lines(x) = left(trim(lines(x)), len(trim(lines(x)))-1) -
loop -
next
then open the file to write and write each line to the fi le followed by the new line character. Let me know if this makes sense. Post Comments |
|
Re: Sorry
|
Pullatti Jamaica |
|
12/20/2007 10:00:47 PM |
Sorry I'm a little dense and I'm new to programming. Are you able to clarify? Post Comments |
|
Re: I don't believe
|
Henri Teipel |
|
12/20/2007 10:20:06 PM |
No, I don't believe you are dense whether you are new to programming or not. Look back at post 31 where I posted the full revised code. Starting in line 16 I open the file to read and I make a series of variables (an "array") with names "lines(0)", "lines(1)", "lines(2)" etc. I suggested in my last post that you copy this exact segment of code again at the end of the script so you have an updated version of the csv file in your array "lines()". You can follow this up with the code I posted in the last post which removes all of the trailing commas from each line. You with me so far?
The only part of this that's a little bit tricky is re-saving the updated version. I believe you can figure out how to do this. I did something very similar to what you might want to do starting in line 59. In my post I showed how to write all of the form data into the file. At this point, youwill want to re-write all of the revised file whick you would have saved in the array lines(). following the open the file line (like line 59) you might say this: Code: ( asp ) -
for each x in lines -
objTxt.write lines(x) & vbNewLine -
next
It's a good idea to close the text object after you use it, but it's not strictly required unless you are going to use it again.
I believe you can figure this out. Most of us got to where we are in our level of skills by trying it even when we weren't sure what we were doing. Sometimes we say this mantra: when in doubt, try it out.
Post Comments |
|
Re: The end of the script
|
Pullatti Jamaica |
|
12/20/2007 10:21:37 PM |
Based on your suggestions, I added this to the end of the script:
Code: ( text ) - set objTXT = objFSO.openTextFile(filePath, 1) 'opens a text file for
-
' reading, true means it will create the file if not already there -
fullText = trim(objTXT.readall) -
lines = split(fullText, vbNewLine) 'lines is now an array, each item is -
' one line of the db file.this could now be used to list the entire db -
' table, notice next 3 commented out lines -
for each x in lines -
do until right(trim(lines(x)),1) <> ","
-
lines(x) = left(trim(lines(x)), len(trim(lines(x)))-1) -
loop - next
- set objTXT = objFSO.openTextFile(filePath, 2, True) 'opens the text file for
-
' writing -
response.write "field names enterd:<br>" & vbNewLine -
for each x in lines -
-
objTxt.write lines(x) & vbNewLine - next
It's still not working so I'm sure I did something wrong. Any thoughts?
Thanks! Post Comments |
|
Re: Error?
|
Henri Teipel |
|
12/20/2007 10:22:32 PM |
What error does this give you? (or does it give no error but nothing happens?) Post Comments |
|
Re: No error
|
Pullatti Jamaica |
|
12/20/2007 10:24:56 PM |
No error and nothing happens. Post Comments |
|
Re: That is odd
|
Henri Teipel |
|
12/20/2007 10:25:57 PM |
That is odd. A lot of things can go wrong when using the fileSystemObject, but they always giv e errors. You don't happen to have an "on error..." line do you? Did you put in an include file? Can you post a link? Post Comments |
|
Re: Here are the links
|
Pullatti Jamaica |
|
12/20/2007 10:28:23 PM |
Here are links: www.rwgarcia.com/forms/formhandler.asp [removed because of private info]
Here is the code in the formhandler file:
Code: ( text ) - <% option explicit
- dim objFSO, objTXT, lines, newRecord, filePath, fieldNames, x, fullText, nLine %>
- <h1>Form inputs posted:</h1>
- <%
- for each x in request.form
-
response.write x & ": " & request.form(x) & "<br>" & vbNewLine - next
- 'set filepath for plain text db.
This neds to be the absolute path of file - filePath = "../private/veggiechips.csv"
- set objFSO = server.createobject("Scripting.FileSystemObject")
- if (objFSO.fileExists(filePath))=true then
-
set objTXT = objFSO.openTextFile(filePath, 1) 'opens a text file for -
' reading, true means it will create the file if not already there -
fullText = trim(objTXT.readall) -
lines = split(fullText, vbNewLine) 'lines is now an array, each item is -
' one line of the db file.this could now be used to list the entire db -
' table, notice next 3 commented out lines -
' for each x in lines -
' response.write lines(x) -
' next -
objTXT.close -
set objTXT = nothing -
if trim(lines(0)) = "" then fullText = ""
- else
-
fullText = ""
- end if %>
- <h1>added to the db:</h1>
- <%
- if fullText <>
"" then 'there are already field names in the db, -
' so put the new line in the same order -
set objTXT = objFSO.openTextFile(filePath, 8, True) 'opens the text file for -
' appending -
response.write "(fields in the database: " & lines(0) & ")<br>" & vbNewLine -
'split the first line, which had field names into an array -fieldNames- -
fieldNames = split(lines(0), ",") -
response.write "field values entered:<br>" & vbNewLine -
for each x in fieldNames -
if x <> "" then -
nLine = nLine & request.form(x) & ","
-
'adds each form input to a string -
response.write x & ": " & request.form(x) & "<br>" & vbNewLine -
end if -
next -
nLine = left(nLine, len(nLine)-1) -
'removes trailing comma -
objTXT.writeLine nLine - else 'there isn't anything in the textfile yet, so put in the field names first
-
set objTXT = objFSO.openTextFile(filePath, 2, True) 'opens the text file for -
' writing -
response.write "field names enterd:<br>" & vbNewLine -
for each x in request.form -
if lcase(x) <> "submit" then 'or you will have a "submit" field in your db -
'of course, if your submit button is named something else, that should -
'be the name xcluded here -
nLine = nLine & x & ","
-
'adds each form input name to a string which will become th first line of -
'the db, the line which shows field names -
response.write x & "<br>" & vbNewLine -
end if -
next -
nLine = left(nLine, len(nLine)-1) -
'remove trailing comma -
objTXT.write nLine -
objTXT.write vbNewLine -
nLine = ""
-
response.write "field values entered:<br>" & vbNewLine -
for each x in request.form -
if lcase(x) <> "submit" then -
nLine = nLine & request.form(x) & ","
-
'adds each form input to a string -
response.write request.form(x) & "<br>" & vbNewLine -
end if -
next -
nLine = left(nLine, len(nLine)-1) -
'remove trailing comma -
objTXT.write nLine -
objTXT.write vbNewLine - end if
- objTXT.close
- response.redirect "veggie_thankyou.shtml"
- set objTXT = objFSO.openTextFile(filePath, 1) 'opens a text file for
-
' reading, true means it will create the file if not already there -
fullText = trim(objTXT.readall) -
lines = split(fullText, vbNewLine) 'lines is now an array, each item is -
' one line of the db file.this could now be used to list the entire db -
' table, notice next 3 commented out lines -
for each x in lines -
do until right(trim(lines(x)),1) <> ","
-
lines(x) = left(trim(lines(x)), len(trim(lines(x)))-1) -
loop - next
- set objTXT = objFSO.openTextFile(filePath, 2, True) 'opens the text file for
-
' writing -
response.write "field names enterd:<br>" & vbNewLine -
for each x in lines -
-
objTxt.write lines(x) & vbNewLine - next
-
- %>
Post Comments |
|
Re: Mistake is silly!
|
Henri Teipel |
|
12/20/2007 10:30:09 PM |
Silly mistake! Notice that you start the code we discussed to trim commas off of each line in line 100, but you redirect to a different page before you even get there... in line 98. You just need to move your redirect line to the end. ;-)
Try it and let me see. I'll run your code as well to make sure it works, but it looks good. Post Comments |
|
Re: Error
|
Tom Garvey |
|
12/20/2007 10:32:01 PM |
when I tried to open the file in excel it gave an error, but this is just because it (excel) ignores every column past some arbitrary number (256? Maybe not so arbitrary) so the error is just saying that excel is ignoring the last of those commas. No big deal.
Post Comments |
|
Re: Notice!!
|
Henri Teipel |
|
12/20/2007 11:00:24 PM |
One other thing which you may not have noticed. When I try to make simple solutions, sometimes I leave out things which I figure different folks should come up with by themselves. This may mean that novices leave really obvious holes in the program. Sorry about that. Any comma that a user types in to any input will mess up the csv file. It will still probably be readable, b ut some inputs will be split up over two cells when opened in excel, and this is obviously no t desired. the solution is to replace any comma that a user might enter with an appropriate ch aracter code, for example "," Post Comments |
|
Re: Thankyou code
|
Pullatti Jamaica |
|
12/20/2007 11:02:35 PM |
I tried moving the thankyou code to the bottom and got this error: HTTP 500.100 - Internal Server Error - ASP error Apache
I had to take out the code at the end because the form went live yesterday and I need to keep it functional.
Any ideas? Post Comments |
|
|
|
|
|
|
|
|
|
|
|
|
|
|