Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: reading name/value pairs from text file.


Message #1 by "Josh Millstein" <shizny@y...> on Wed, 4 Sep 2002 06:58:19
I have a form on an asp page with the following three different varieties
of variables

monthCaptions1 ... monthCaptions12
monthText1 ... monthText12
monthImages1 ... monthImages12

so there are 36 fields in the form (12x3).  I would like to write the input
from a user to a text file.  I have that working.  So the file looks like 

monthCaptions1=the captions for the month1&monthText1=events
somewhere&monthImages1=john.jpg& .. ....

you get the drift.  Now what I would like to do is read in that file when
the form asp page is called and preload any fields that match the form.  So
for example if the txt file just had all the January Stuff completed then
when the page opened the form fields would be filled w/ information from
the file.  That way the user doesn't always have to "refill" the form
fields that they want to stay the same so that it can be written to file. 
Anybody got any ideas?
Message #2 by "phil griffiths" <pgtips@m...> on Wed, 4 Sep 2002 08:52:17
You could just use cookies.  You can either use client-side or server-side 
code to store and retrieve them.

HTH
Phil
>----------------------------------------------
I have a form on an asp page with the following three different varieties
of variables

monthCaptions1 ... monthCaptions12
monthText1 ... monthText12
monthImages1 ... monthImages12

so there are 36 fields in the form (12x3).  I would like to write the input
from a user to a text file.  I have that working.  So the file looks like 

monthCaptions1=the captions for the month1&monthText1=events
somewhere&monthImages1=john.jpg& .. ....

you get the drift.  Now what I would like to do is read in that file when
the form asp page is called and preload any fields that match the form.  So
for example if the txt file just had all the January Stuff completed then
when the page opened the form fields would be filled w/ information from
the file.  That way the user doesn't always have to "refill" the form
fields that they want to stay the same so that it can be written to file. 
Anybody got any ideas?
>-----------------------------------------------
Message #3 by "Josh Millstein" <shizny@y...> on Wed, 4 Sep 2002 16:00:30
I'm using this info for dynamic text/images withing a flash movie.  Why
should I use cookies and if I do I would want to use serverside wouldn't I
and do you have any examples on how this would work.

Thanks.

> You could just use cookies.  You can either use client-side or server-side 
c> ode to store and retrieve them.

> HTH
P> hil
>> ----------------------------------------------
I>  have a form on an asp page with the following three different varieties
o> f variables

> monthCaptions1 ... monthCaptions12
m> onthText1 ... monthText12
m> onthImages1 ... monthImages12

> so there are 36 fields in the form (12x3).  I would like to write the input
f> rom a user to a text file.  I have that working.  So the file looks like 

> monthCaptions1=the captions for the month1&monthText1=events
s> omewhere&monthImages1=john.jpg& .. ....

> you get the drift.  Now what I would like to do is read in that file when
t> he form asp page is called and preload any fields that match the form.  So
f> or example if the txt file just had all the January Stuff completed then
w> hen the page opened the form fields would be filled w/ information from
t> he file.  That way the user doesn't always have to "refill" the form
f> ields that they want to stay the same so that it can be written to file. 
A> nybody got any ideas?
>> -----------------------------------------------
Message #4 by "phil griffiths" <pgtips@m...> on Thu, 5 Sep 2002 09:03:18
>Why should I use cookies 
Because they can do what you want, in fact that's what they were designed 
for - persisting values between pages or between visits to the same page.  
To me, writing values to/from text files is desktop app thinking.  

>if I do I would want to use serverside wouldn't I
Depends how much JS you know and whether you want to expose that script to 
clients

>and do you have any examples on how this would work.
to set a cookie for the browser session:
Response.Cookies("name") = "value"

to get a cookie:
var = Request.Cookies("name")

what else do you need?
rgds
Phil
Message #5 by "Josh Millstein" <shizny@y...> on Thu, 5 Sep 2002 16:27:29
Thanks for the help so far.  I think we may be a little off on what I'm
trying to do.  I want this information (name/value pairs) to be put up on
the web page in certain spots.  It doesn't matter who the viewer is so the
cookies wouldn't really be stored on the users machine.  The information
will be the same for every user.  I have a field on my web page that is
called monthText1... I want the web page to load the information from the
cookie and display it in the area it needs to be.  
I guess my question is how to write the cookie to the server side?
I know the Response.Cookies("name") = value deal but how do you specify the
location that the cookie is being created from/ read from?
I have seen the code on how to write to the user's machine but haven't seen
of or read of anything describing how to write the cookie to the server
side.  Once again thanks for your help.

Josh

> >Why should I use cookies 
B> ecause they can do what you want, in fact that's what they were designed 
f> or - persisting values between pages or between visits to the same page.  
T> o me, writing values to/from text files is desktop app thinking.  

> >if I do I would want to use serverside wouldn't I
D> epends how much JS you know and whether you want to expose that script to 
c> lients

> >and do you have any examples on how this would work.
t> o set a cookie for the browser session:
R> esponse.Cookies("name") = "value"

> to get a cookie:
v> ar = Request.Cookies("name")

> what else do you need?
r> gds
P> hil
Message #6 by "phil griffiths" <pgtips@m...> on Fri, 6 Sep 2002 09:34:16
OK, I misunderstood your requirement.

In that case forget cookies, they're for client-side only.  If you've 
already got the values saved in a text file on the server then you just 
need to use the filesystem object to read that file, then maybe use 
split() to get the values from that file.  Finally, write the values out 
to the page.

The only thing you need to decide is when you read the text file.  You 
could read it each time you need to display the web page(s), or you could 
read it in Application_OnStart and store the values in Application 
variables (and save them back to text file in Application_OnEnd).

Which bit are you having problems with?  Reading the file, or writing the 
values to the page?

rgds
Phil
>-----------------------------------------------
Thanks for the help so far.  I think we may be a little off on what I'm
trying to do.  I want this information (name/value pairs) to be put up on
the web page in certain spots.  It doesn't matter who the viewer is so the
cookies wouldn't really be stored on the users machine.  The information
will be the same for every user.  I have a field on my web page that is
called monthText1... I want the web page to load the information from the
cookie and display it in the area it needs to be.  
I guess my question is how to write the cookie to the server side?
I know the Response.Cookies("name") = value deal but how do you specify the
location that the cookie is being created from/ read from?
I have seen the code on how to write to the user's machine but haven't seen
of or read of anything describing how to write the cookie to the server
side.  Once again thanks for your help.

Josh

  Return to Index