|
| |
|
|
funkdrmr
Posts: 15 Joined: 9/4/2002 Status: offline
|
Saving Entered Data into Unique Text Files - 9/4/2002 3:01:12
I am stationed onboard a submarine in the U.S. Navy. I have created an Intranet for our boat using FP2002, however I have 1 problem. To address this, please let me give some background. To send e-mail from our boat, all hands create a text file and then e-mail it to the personnel that send it off the boat. On the Intranet, my goal is to have a text box, where personnel can type their entries, but that is where the easy part for me stops. The unique problem for me is that I need the text that is submitted to be saved to a different text file EVERY time it is sent. Is there a way to have this form create a uniquely named text file and save that text each time, instead of having every person' s entry saved to the same file?
|
|
|
|
funkdrmr
Posts: 15 Joined: 9/4/2002 Status: offline
|
RE: Saving Entered Data into Unique Text Files - 9/4/2002 21:40:44
Thanks for the response! It' s too bad that I don' t have ANY knowledge of ASP, but what a great time to learn. [:j] It' s going slow, but a question that I' ve come against is how do I associate the FSO with the Form that I' m creating with the ASP? TIA for anymore input.
|
|
|
|
Doug G
Posts: 1189 Joined: 12/29/2001 From: SoCal Status: offline
|
RE: Saving Entered Data into Unique Text Files - 9/5/2002 22:49:01
quote:
So, does this mean I actually need 2 web pages to accomplish this? One, the .htm page with the form in it, which submits to the .asp that has the FSO code within it? I hope I' m getting on the right track here!!! Thanks for the informational reply! Yes, unless you are feeling frisky and decide to use just one asp page that posts to itself! It' s quite common with asp to put the " receiving" asp code near the top of your asp page, and the user form lower down in the page, and pass a control value via the querystring (or hidden field, or ...) Here' s a quick skeleton that shows the basics. I didn' t actually run or test this so any typo' s must be because of a server problem or somethin [:p] <% If request.querystring(" mode" ) = " posted" Then ' The asp code to process the user' s form value = doWhatever(request.form(" myinput" ) ' Call an asp function somewhere response.redirect " someotherpage.asp" ' Go somewhere else when done processing input. ' Else ' The form HTML begins below the asp delimiter %> %> <form name=" myform" method=" post" action=" samepage.asp?mode=" " posted" " " > <input name=" myinput" blah blah> <input type=" submit" > </form> <% End If ' Gotta close the if statement out %>
< Message edited by Doug G -- 9/4/2002 10:50:02 PM >
_____________________________
====== Doug G ======
|
|
|
|
funkdrmr
Posts: 15 Joined: 9/4/2002 Status: offline
|
RE: Saving Entered Data into Unique Text Files - 9/6/2002 1:04:17
OK guys. Hopefully, again, I' m taking all of this new information in correctly and doing ok. Here' s where I' m at. I have created 2 .asp pages. The first page has the form, which the user will type in, and NOW includes (thanks Doug) <form method=" POST" action=" response.asp" > So what I' ve taken from this, is I am telling the form to post to another page titled response.asp. I then created my second page, titled response.asp. In it, I have the following lines of code: <% Const fsoTempFolder = 2 Dim objFSO Set objFSO = Server.CreateObject(" Scripting.FileSystemObject" ) Dim strTempFolder, strTempFileName strTempfolder = objFSO.GetSPecialFolder(fsoTempFolder) strTempFileName = strTempFolder & " \" & objFSO.GetTempName() Response.Write " The temporary folder is: " & strTempFolder Response.Write " <br>A temp. file name: " & strTempFileName Set objFSO = Nothing ' Clean up! %> The end result, is when the form submits, it seems to post to " response.asp" . When response comes up, it shows me the temp directory and random file name that it has chosen to save my file as....HOWEVER...no files exist. So.....I guess what I need to know now, is how I can get these files to generate. Also, if there is a way that I can save the file with a different extension, instead of .tmp, or if I could specify a certain directory, that would be great, but not completely necessary at this time. Thanks again for all the information. In 2 days, I' ve learned more than I' ve ever wondered about ASP!
|
|
|
|
funkdrmr
Posts: 15 Joined: 9/4/2002 Status: offline
|
RE: Saving Entered Data into Unique Text Files - 9/6/2002 19:39:19
Sorry about posting 2 messages before a reply, but I don' t want to have to back track on all this good advice! I can now generate the random file, create it, and write a message to it, although it isn' t what is entered in the box. Here' s the code again that I' m using: <% Const fsoTempFolder = 2 Dim objFSO, objTS Set objFSO = Server.CreateObject(" Scripting.FileSystemObject" ) Dim strTempFolder, strTempFileName strTempfolder = objFSO.GetSPecialFolder(fsoTempFolder) strTempFileName = strTempFolder & " \" & objFSO.GetTempName() ' Create the text file Set ObjTS = objFSO.CreateTextFile(strTempFileName) ' Write email to the file objTS.WriteLine(" Howdy" ) Response.Write " The temporary folder is: " & strTempFolder Response.Write " <br>A temp. file name: " & strTempFileName Set objFSO = Nothing ' Clean up! %> The bold entries are the new additions. I think what I am missing is a way to address the form on the 1st page to this second page. After I can accomplist writing the text to the created file, I' ll be trying to find a way to specify the directory where the file is saved, as well as changing the filename extension to .eml. If I could get any more info, I' d be eternally greatful!
|
|
|
|
funkdrmr
Posts: 15 Joined: 9/4/2002 Status: offline
|
RE: Saving Entered Data into Unique Text Files - 9/6/2002 20:59:44
WOOHOO!!! Another step closer! Here' s the code I have now, with the newer entries in BOLDI' ll post my remaining questions after it: <% Const fsoTempFolder = 2 Dim objFSO, objTS Set objFSO = Server.CreateObject(" Scripting.FileSystemObject" ) Dim strTempFolder, strTempFileName strTempfolder = objFSO.GetSPecialFolder(fsoTempFolder) strTempFileName = strTempFolder & " \" & objFSO.GetTempName() ' Create the text file Set ObjTS = objFSO.CreateTextFile(strTempFileName) Request.Form(" Sailor_Mail" ) ' Write email to the file ObjTS.WriteLine Request.Form(" Sailor_Mail" ) Response.Write " The temporary folder is: " & strTempFolder Response.Write " <br>A temp. file name: " & strTempFileName Set objFSO = Nothing ' Clean up! %> As I' m sure you' ve figured out, the form on my 1st page is named Sailor_Mail. After looking up some of the advice you guys have given, as well as searching for as much as I could find, I noticed the WriteLine command. Adding that with the Request.Form command, and BINGO!!! The code now generates a randomly named .tmp file, and saves the text entered in my form on the first page within it! Now for the finishing touches, and (I promise ) my final questions. Is there a way that I can specify which directory the files are saved to (currently, it is C:\WINN)? Also, how can I change the file extension from .tmp to .txt or .eml?? Thanks again for your help. I look forward to reading the replies soon!
|
|
|
|
Doug G
Posts: 1189 Joined: 12/29/2001 From: SoCal Status: offline
|
RE: Saving Entered Data into Unique Text Files - 9/7/2002 13:06:07
One easy way is this strTempFileName = strTempFolder & " \" & objFSO.GetTempName() & " .txt" You end up with something like " \folder\13244234234.tmp.txt" which is fine in most versions of windows. If you want to remove the .tmp extension, use something like below (I did it a line at a time so you can see what' s going on). A temp filename with your extension will end up in s1. I haven' t tested this for any syntax errors but should give you the general idea. s1 = objFSO.GetTempName() s1 = StrReverse(s1), s1 = Mid(s1, Instr(s1, " ." , len(s1)) s1 = StrReverse(s1) s1 = s1 & " .eml"
_____________________________
====== Doug G ======
|
|
|
|
funkdrmr
Posts: 15 Joined: 9/4/2002 Status: offline
|
RE: Saving Entered Data into Unique Text Files - 9/7/2002 16:26:06
Ok...I have the file saving to where I want it to now. It' s amazing what a few hours away from the screen will wake you up to. Instead of using ObjFSO.GetSPecialFolder(fsoTempFolder) for strTempfolder, I specified the C:\email folder, and it worked like a charm. Now, on to the file renaming! Looking at your code, Doug, it made sense to me (for what little I have of ASP, anyways ) I am now, however, receiving an error stating Type mismatch: ' s1' , and the browser is kind enough to tell me that it' s within Line 24, which happens to be the following line: s1 = Mid(s1, Instr(s1, " ." , len(s1)) At first, IE told me it was expecting ' )' at the end, so I added that (making 3 instad of the 2 that you posted), and now it comes up with the type mismatch error. With all of the fiddling around I' m doing with it, I believe this will be my last error once it' s resolved. I' ve tried putting the code all on 1 line, or just like you typed it in the last post, but neither comes out correctly. Does is really make a difference how the code is input? Well, I' ll be anxiously awaiting anymore info that I can sqeeze outta you guys. Obviously, if I figure it out, I' ll post here, so we don' t have to mess with this anymore. Thanks again!
|
|
|
|
Doug G
Posts: 1189 Joined: 12/29/2001 From: SoCal Status: offline
|
RE: Saving Entered Data into Unique Text Files - 9/7/2002 21:02:45
That' s because there is an error in the code I posted. There is a missing parentheses s1 = Mid(s1, Instr(s1, " ." , len(s1)) should be s1 = Mid(s1, Instr(s1, " ." ), len(s1)) InStr() returns the character position of the " ." in the s1 string (I just used s1 as a variable name ' cause it' s short and easy to type). Mid returns a substring from the s1 string, beginning at the " ." character position and extending to the end of the s1 string. Other lines reversed the s1 string before we did this, and then another reversal after this line puts the string back in the right order but minus the file extension. hth
_____________________________
====== Doug G ======
|
|
|
|
funkdrmr
Posts: 15 Joined: 9/4/2002 Status: offline
|
RE: Saving Entered Data into Unique Text Files - 9/8/2002 1:36:13
IT WORKS!!!!!!!!!! Here is the code for this week-long adventure! <% Const fsoTempFolder = 2 Dim objFSO, objTS Set objFSO = Server.CreateObject(" Scripting.FileSystemObject" ) Dim strTempFolder, strTempFileName, strTextFileName strTempfolder = " C:\email" strTempFileName = strTempFolder & " \" & objFSO.GetTempName() & " .eml" ' Create the text file Set ObjTS = objFSO.CreateTextFile(strTempFileName) ' Request the form to be written to the file Request.Form(" Sailor_Mail" ) ' Write email from form to the file ObjTS.WriteLine Request.Form(" Sailor_Mail" ) ' Change tmp filename to eml extension s1=objFSO.GetTempName() s1=StrReverse(s1) s1=Mid(s1, Instr(s1," ." ),len(s1)) s1=StrReverse(s1) s1=s1 & " .eml" Response.Write " Your e-mail was saved on the server at: " & strTempFolder Response.Write " <br>The name of your saved e-mail file is: " & strTempFileName Set objFSO = Nothing ' Clean up! %> To Spooky, Bobby, and Doug, I can' t thank you all enough! I could have never done this without your help. In retrospect, I am extremely appreciative that you did not just write the code out for me. Most of your replies contained links for me to RESEARCH, which made me learn, which allowed me to actually customize a good chunk of this by myself, rather than ask every little line.... Honestly, I thank you guys very much. If any of you are ever in the Seattle area, San Diego, or Hawaii, e-mail me and I' ll see about getting you a tour on our sub as a token of my appreciation. If you need my e-mail, go to www.ussasheville.com My address is on the FT2 Smith link at the bottom. I can' t promise anything until that time comes, but hey, we' ll give it our best shot. Until next time, thanks again!!!
|
|
|
|
Doug G
Posts: 1189 Joined: 12/29/2001 From: SoCal Status: offline
|
RE: Saving Entered Data into Unique Text Files - 9/8/2002 12:27:21
Two small things. One, don' t add the " .eml" on the line where you get the temporary file name. By doing so, later on that' s the extension you remove and then readd, ending up with a name like 2347u234.tmp.eml The " extension removal" code just removes the last file extension. Also, you probably should Dim the s1 variable.
_____________________________
====== Doug G ======
|
|
|
|
funkdrmr
Posts: 15 Joined: 9/4/2002 Status: offline
|
RE: Saving Entered Data into Unique Text Files - 9/8/2002 14:46:38
AHH! That' s why the " .tmp.eml" is happening! LOL! I was just gonna write a script to take the .tmp out! LOL Glad to know it can be fixed like that. I was so excited that it worked, I just hadn' t worried about it. Two quick questions: in the line where I get the Temp File name, should I change the .eml back to .tmp? Or just delete that part all together? Also, just out of curiosity, what actually happens when I " Dim" the s1 variable. I understand where to put it within the scheme of things, just not 100% what that does for me. Thanks again!
|
|
|
|
Doug G
Posts: 1189 Joined: 12/29/2001 From: SoCal Status: offline
|
RE: Saving Entered Data into Unique Text Files - 9/8/2002 17:00:22
change strTempFileName = strTempFolder & " \" & objFSO.GetTempName() & " .eml" to strTempFileName = strTempFolder & " \" & objFSO.GetTempName() The GetTempName method apparently adds the .tmp extension to the name it gives you. Dim a variable to tell the interpreter that the variable exists so it can preallocate space for the variable in memory. You don' t have to Dim variables unless you use the Option Explicit statement (which I always use). Option Explicit will generate an error if you don' t Dim a variable before you try to use it. This is good, it helps you catch typos & such.
_____________________________
====== Doug G ======
|
|
|
|
funkdrmr
Posts: 15 Joined: 9/4/2002 Status: offline
|
RE: Saving Entered Data into Unique Text Files - 9/9/2002 17:12:55
One more time...here' s what I' ve got <% Const fsoTempFolder = 2 Dim objFSO, objTS Set objFSO = Server.CreateObject(" Scripting.FileSystemObject" ) Dim strTempFolder, strTempFileName strTempfolder = " C:\email" strTempFileName = strTempFolder & " \" & objFSO.GetTempName() ' Create the text file Set ObjTS = objFSO.CreateTextFile(strTempFileName) ' Request the form to be written to the file Request.Form(" Sailor_Mail" ) ' Write email from form to the file ObjTS.WriteLine Request.Form(" Sailor_Mail" ) ' Change tmp filename to eml extension Dim s1 s1=objFSO.GetTempName() s1=StrReverse(s1) s1=Mid(s1, Instr(s1," ." ),len(s1)) s1=StrReverse(s1) s1=s1&" .eml" Response.Write " Your e-mail was saved on the server at: " & strTempFolder Response.Write " <br>The name of your saved e-mail file is: " & strTempFileName Set objFSO = Nothing ' Clean up! %> I' ve edited everything as suggested, but I' m still only getting a .tmp file. Before, I was getting .tmp.eml, which was a little better. So close, yet so far away. I' m actually at a loss for words at this point, because from what I have, it makes sense to work. So, I' m not seeing anywhere here where the problem could be lying. Any suggestions, including deal with the .tmp.eml, would be appreciated.
|
|
|
|
Doug G
Posts: 1189 Joined: 12/29/2001 From: SoCal Status: offline
|
RE: Saving Entered Data into Unique Text Files - 9/9/2002 21:50:43
It' s because I threw together a sample using s1 as a variable name, but you never use the s1 filename in your code. You get your temp filename and create your temp file before you do any file extension changing, and never see the results of your hard work. Try this: <% Const fsoTempFolder = 2 Dim objFSO, objTS Dim s1 Set objFSO = Server.CreateObject(" Scripting.FileSystemObject" ) Dim strTempFolder, strTempFileName strTempfolder = " C:\email" ' Change tmp filename to eml extension s1=objFSO.GetTempName() s1=StrReverse(s1) s1=Mid(s1, Instr(s1," ." ),len(s1)) s1=StrReverse(s1) s1=s1&" .eml" strTempFileName = strTempFolder & " \" & s1 ' <<---note the change here ' Create the text file Set ObjTS = objFSO.CreateTextFile(strTempFileName) ' Request the form to be written to the file Request.Form(" Sailor_Mail" ) ' Write email from form to the file ObjTS.WriteLine Request.Form(" Sailor_Mail" ) Response.Write " Your e-mail was saved on the server at: " & strTempFolder Response.Write " <br>The name of your saved e-mail file is: " & strTempFileName Set objFSO = Nothing ' Clean up! %> The filesystem object creates the temp filename for you into a variable named s1. Next, that filename is massaged to change the .tmp extension to .eml Then the temp filename in the variable s1 is tacked on the end of the path to create your strTempFileName variable, and then you create the temp file with the name you want. You don' t have to use a separate variable s1, I use s1 as a localized temporary string variable a lot ' cause I' m a lazy typist, and I don' t like typing strTempFileName over and over
_____________________________
====== Doug G ======
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|