HI,
I have set up a page with a form which appends data to a .csv file on my asp
server, this is to enable a limited number of users to add news threads to
this file, which contains the data in the following format
(date,headline,article);
"181003","news title","news article"
"171003","older news title","news article"
The form adds the data in reverse chronological order with newest at the top
of the list.
Now I wish to be able to write the contents of the csv file to a table cell,
formatted the same as the rest of the page (if I use the include tag I get
unformatted text and all the speach marks and no paragraph tag in between
items).
I am new to javascript and asp, although I do have a basic understanding of
how they work.
Could someone kindly explain the best way to achieve this, I'm not looking
for someone to do my hard work for me nessacerely, if it isn't possible to
show me the coding needed, just an explanation will help greatly.
Many thanks in advance
StumpY 14 5210
StumpY wrote: HI, I have set up a page with a form which appends data to a .csv file on my asp server, this is to enable a limited number of users to add news threads to this file, which contains the data in the following format (date,headline,article); "181003","news title","news article" "171003","older news title","news article" The form adds the data in reverse chronological order with newest at the top of the list. Now I wish to be able to write the contents of the csv file to a table cell, formatted the same as the rest of the page (if I use the include tag I get unformatted text and all the speach marks and no paragraph tag in between items). I am new to javascript and asp, although I do have a basic understanding of how they work. Could someone kindly explain the best way to achieve this, I'm not looking for someone to do my hard work for me nessacerely, if it isn't possible to show me the coding needed, just an explanation will help greatly. Many thanks in advance StumpY http://groups.google.com/groups?hl=e...tel.net&rnum=9
N1 - is there any way to automate this procedure? I want my users to have
as little 'access' to the site as possible.
Cheers for the reply
"Fox" <fo*@fxmahoney.com> wrote in message
news:3F***************@fxmahoney.com...
StumpY wrote: HI, I have set up a page with a form which appends data to a .csv file on my
asp server, this is to enable a limited number of users to add news threads
to this file, which contains the data in the following format (date,headline,article); "181003","news title","news article" "171003","older news title","news article" The form adds the data in reverse chronological order with newest at the
top of the list. Now I wish to be able to write the contents of the csv file to a table
cell, formatted the same as the rest of the page (if I use the include tag I
get unformatted text and all the speach marks and no paragraph tag in
between items). I am new to javascript and asp, although I do have a basic understanding
of how they work. Could someone kindly explain the best way to achieve this, I'm not
looking for someone to do my hard work for me nessacerely, if it isn't possible
to show me the coding needed, just an explanation will help greatly. Many thanks in advance StumpY
http://groups.google.com/groups?hl=e...tel.net&rnum=9
Hi,
StumpY wrote: N1 - is there any way to automate this procedure? I want my users to have as little 'access' to the site as possible. Cheers for the reply
"Fox" <fo*@fxmahoney.com> wrote in message news:3F***************@fxmahoney.com...
StumpY wrote:
HI, I have set up a page with a form which appends data to a .csv file on my asp server, this is to enable a limited number of users to add news threads to this file, which contains the data in the following format (date,headline,article); "181003","news title","news article" "171003","older news title","news article" The form adds the data in reverse chronological order with newest at the top of the list. Now I wish to be able to write the contents of the csv file to a table cell, formatted the same as the rest of the page (if I use the include tag I get unformatted text and all the speach marks and no paragraph tag in between items). I am new to javascript and asp, although I do have a basic understanding of how they work. Could someone kindly explain the best way to achieve this, I'm not looking for someone to do my hard work for me nessacerely, if it isn't possible to show me the coding needed, just an explanation will help greatly. Many thanks in advance StumpY
http://groups.google.com/groups?hl=e...tel.net&rnum=9
Fox didn't see that you have ASP, so what you're looking for is a
server-side solution.
On ASP, the procedure would be to:
1) Load the text file, using the FileSystemObject.
2) For each line, split the line in fields in a JavaScript array, using
the method strLine.split( "," ); where strLine is the line read form the
text file.
3) Build your table using the array's fields in a string.
4) Pass the built string in the Response object, like:
Response.Write( strHtml );
If you have troubles implementing this, ask me and I can provide you
with a small example.
HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript : http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
StumpY wrote: N1 - is there any way to automate this procedure? I want my users to have as little 'access' to the site as possible. Cheers for the reply
The following is OffTopic
Use PHP -- it has a function specifically designed to read csv files.
<?php
// need to get how many records in file
// if your data file uses column labels
// remember to "burn off" the first record!
// this example ASSUMES your csv looks like:
// date,headline,article => column labels
// "181003","news title","news article"
// "171003","older news title","news article"
function
getNumRecords($h)
{
$cnt = -1; // discount column label row
// otherwise $cnt = 0;
while(fgetcsv($h, 10000)) $cnt++;
rewind($h); // reset file pointer to beginning
return $cnt;
}
$handle = fopen("myNews.csv","r");
$cnt = getNumRecords($handle);
echo "<script>\n\n";
echo "var newsdata = [\n\t\t";
fgetcsv($handle, 10000); // burn off labels
for($i = 0; $i < $cnt; $i++)
{
$data = fgetcsv($handle, 10000);
$cols = count($data);
echo "[";
for($j = 0; $j < $cols; $j++)
echo "\"" . $data[$j] . "\"" . ($j < $cols-1 ? "," : "");
echo "]" . ($i < $cnt - 1 ? "," : "") . "\n\t\t";
}
echo "];\n\n";
echo "</script>";
?>
The output from this will look like:
<script>
var newsdata = [
["181003","news title","news article"],
["171003","older news title","news aritcle"]
];
</script>
This PHP script does basically the same thing as the form routine I
linked you to.
The function fgetcsv takes care of stripping the quotes from "cell"
entries containing commas and the number of entries is correctly
returned -- no special handling should be needed [I'm not sure what
happens with quotes used in the data -- you'll probably need to
experiment with that [but I wouldn't be surprised if the function took
care of escaping it for you].
The arguments to fgetcsv are (obviously) the reference returned from
fopen and the *length* of the line to be returned -- note, the length
MUST be greater than the total number of characters in the longest line
within the file if you expect to retrieve all your data. "Fox" <fo*@fxmahoney.com> wrote in message news:3F***************@fxmahoney.com...
StumpY wrote: HI, I have set up a page with a form which appends data to a .csv file on my asp server, this is to enable a limited number of users to add news threads to this file, which contains the data in the following format (date,headline,article); "181003","news title","news article" "171003","older news title","news article" The form adds the data in reverse chronological order with newest at the top of the list. Now I wish to be able to write the contents of the csv file to a table cell, formatted the same as the rest of the page (if I use the include tag I get unformatted text and all the speach marks and no paragraph tag in between items). I am new to javascript and asp, although I do have a basic understanding of how they work. Could someone kindly explain the best way to achieve this, I'm not looking for someone to do my hard work for me nessacerely, if it isn't possible to show me the coding needed, just an explanation will help greatly. Many thanks in advance StumpY
http://groups.google.com/groups?hl=e...tel.net&rnum=9
Cheers Fox - but I've got no PHP feature available (MS Hosting)
Stumpy
"Fox" <fo*@fxmahoney.com> wrote in message
news:3F**************@fxmahoney.com...
StumpY wrote: N1 - is there any way to automate this procedure? I want my users to
have as little 'access' to the site as possible. Cheers for the reply
The following is OffTopic
Use PHP -- it has a function specifically designed to read csv files.
<?php
// need to get how many records in file // if your data file uses column labels // remember to "burn off" the first record! // this example ASSUMES your csv looks like:
// date,headline,article => column labels // "181003","news title","news article" // "171003","older news title","news article"
function getNumRecords($h) { $cnt = -1; // discount column label row // otherwise $cnt = 0;
while(fgetcsv($h, 10000)) $cnt++; rewind($h); // reset file pointer to beginning return $cnt; }
$handle = fopen("myNews.csv","r");
$cnt = getNumRecords($handle);
echo "<script>\n\n"; echo "var newsdata = [\n\t\t";
fgetcsv($handle, 10000); // burn off labels
for($i = 0; $i < $cnt; $i++) { $data = fgetcsv($handle, 10000); $cols = count($data); echo "[";
for($j = 0; $j < $cols; $j++) echo "\"" . $data[$j] . "\"" . ($j < $cols-1 ? "," : "");
echo "]" . ($i < $cnt - 1 ? "," : "") . "\n\t\t"; }
echo "];\n\n"; echo "</script>";
?>
The output from this will look like:
<script>
var newsdata = [ ["181003","news title","news article"], ["171003","older news title","news aritcle"] ];
</script>
This PHP script does basically the same thing as the form routine I linked you to.
The function fgetcsv takes care of stripping the quotes from "cell" entries containing commas and the number of entries is correctly returned -- no special handling should be needed [I'm not sure what happens with quotes used in the data -- you'll probably need to experiment with that [but I wouldn't be surprised if the function took care of escaping it for you].
The arguments to fgetcsv are (obviously) the reference returned from fopen and the *length* of the line to be returned -- note, the length MUST be greater than the total number of characters in the longest line within the file if you expect to retrieve all your data.
"Fox" <fo*@fxmahoney.com> wrote in message news:3F***************@fxmahoney.com...
StumpY wrote: > > HI, > I have set up a page with a form which appends data to a .csv file
on my asp > server, this is to enable a limited number of users to add news
threads to > this file, which contains the data in the following format > (date,headline,article); > "181003","news title","news article" > "171003","older news title","news article" > The form adds the data in reverse chronological order with newest at
the top > of the list. > Now I wish to be able to write the contents of the csv file to a
table cell, > formatted the same as the rest of the page (if I use the include tag
I get > unformatted text and all the speach marks and no paragraph tag in between > items). > I am new to javascript and asp, although I do have a basic
understanding of > how they work. > Could someone kindly explain the best way to achieve this, I'm not looking > for someone to do my hard work for me nessacerely, if it isn't
possible to > show me the coding needed, just an explanation will help greatly. > Many thanks in advance > StumpY
http://groups.google.com/groups?hl=e...tel.net&rnum=9
Hi Laurent,
a small example would be absolutely blinding :)
Cheers for your help
Stumpy
"Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_SPAM.ch> wrote in
message news:3f********@news.bluewin.ch... Hi,
StumpY wrote:
N1 - is there any way to automate this procedure? I want my users to
have as little 'access' to the site as possible. Cheers for the reply
"Fox" <fo*@fxmahoney.com> wrote in message news:3F***************@fxmahoney.com...
StumpY wrote:
HI, I have set up a page with a form which appends data to a .csv file on
my asp
server, this is to enable a limited number of users to add news threads to
this file, which contains the data in the following format (date,headline,article); "181003","news title","news article" "171003","older news title","news article" The form adds the data in reverse chronological order with newest at
the top
of the list. Now I wish to be able to write the contents of the csv file to a table
cell,
formatted the same as the rest of the page (if I use the include tag I
get
unformatted text and all the speach marks and no paragraph tag in
between
items). I am new to javascript and asp, although I do have a basic
understanding of
how they work. Could someone kindly explain the best way to achieve this, I'm not
looking
for someone to do my hard work for me nessacerely, if it isn't possible
to
show me the coding needed, just an explanation will help greatly. Many thanks in advance StumpY
http://groups.google.com/groups?hl=e...tel.net&rnum=9 Fox didn't see that you have ASP, so what you're looking for is a server-side solution.
On ASP, the procedure would be to:
1) Load the text file, using the FileSystemObject. 2) For each line, split the line in fields in a JavaScript array, using the method strLine.split( "," ); where strLine is the line read form the text file. 3) Build your table using the array's fields in a string. 4) Pass the built string in the Response object, like: Response.Write( strHtml );
If you have troubles implementing this, ask me and I can provide you with a small example.
HTH,
Laurent -- Laurent Bugnion, GalaSoft Webdesign, Java, javascript: http://www.galasoft-LB.ch Private/Malaysia: http://mypage.bluewin.ch/lbugnion Support children in Calcutta: http://www.calcutta-espoir.ch
Hi,
StumpY wrote: Hi Laurent,
a small example would be absolutely blinding :)
Cheers for your help
Stumpy
Here is a very simple example. You can modify the table layout in the
line 24 and following.
HTH,
Laurent
----------------------------
<%@Language=JavaScript %>
<HTML>
<HEAD>
<TITLE>GalaSoft</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<%
var NAME_CSV_FILE = "d:\\temp\\test.txt";
var fso = Server.CreateObject( "Scripting.FileSystemObject" );
if ( !fso.FileExists( NAME_CSV_FILE ) )
{
Response.Write( "The file doesn't exist" );
}
else
{
// 1 = ForReading
var fl = fso.OpenTextFile( NAME_CSV_FILE, 1 );
var strTable = "<TABLE BORDER='1'>\n";
while ( !fl.AtEndOfStream )
{
var strLine = fl.ReadLine();
var astrLine = strLine.split( ',' );
// Remove "" from fields
var strDate
= astrLine[0].substring( 1, astrLine[0].length - 1 );
var strTitle
= astrLine[1].substring( 1, astrLine[1].length - 1 );
var strArticle
= astrLine[2].substring( 1, astrLine[2].length - 1 );
var strTableRow = "<TR>\n"
+ "<TD>" + strDate + "</TD>\n"
+ "<TD>" + strTitle + "</TD>\n"
+ "<TD>" + strArticle + "</TD>\n"
+ "</TR>\n";
strTable += strTableRow;
}
strTable += "</TABLE>\n";
Response.Write( strTable );
}
%>
</BODY>
</HTML>
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript : http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Hi,
StumpY wrote: Cheers Fox - but I've got no PHP feature available (MS Hosting) Stumpy
You could install PHP on your host, solutions are available AFAIK.
However, if you have a MS host anyway, you're better off with ASP and
JScript.
Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript : http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Thank you very much - a lifesaver!!
"Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_SPAM.ch> wrote in
message news:bm**********@rex.ip-plus.net... Hi,
StumpY wrote:
Hi Laurent,
a small example would be absolutely blinding :)
Cheers for your help
Stumpy
Here is a very simple example. You can modify the table layout in the line 24 and following.
HTH,
Laurent
---------------------------- <%@Language=JavaScript %>
<HTML> <HEAD> <TITLE>GalaSoft</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF">
<%
var NAME_CSV_FILE = "d:\\temp\\test.txt";
var fso = Server.CreateObject( "Scripting.FileSystemObject" );
if ( !fso.FileExists( NAME_CSV_FILE ) ) { Response.Write( "The file doesn't exist" ); } else { // 1 = ForReading var fl = fso.OpenTextFile( NAME_CSV_FILE, 1 );
var strTable = "<TABLE BORDER='1'>\n";
while ( !fl.AtEndOfStream ) { var strLine = fl.ReadLine(); var astrLine = strLine.split( ',' );
// Remove "" from fields var strDate = astrLine[0].substring( 1, astrLine[0].length - 1 ); var strTitle = astrLine[1].substring( 1, astrLine[1].length - 1 ); var strArticle = astrLine[2].substring( 1, astrLine[2].length - 1 );
var strTableRow = "<TR>\n" + "<TD>" + strDate + "</TD>\n" + "<TD>" + strTitle + "</TD>\n" + "<TD>" + strArticle + "</TD>\n" + "</TR>\n";
strTable += strTableRow; }
strTable += "</TABLE>\n";
Response.Write( strTable ); }
%>
</BODY> </HTML>
-- Laurent Bugnion, GalaSoft Webdesign, Java, javascript: http://www.galasoft-LB.ch Private/Malaysia: http://mypage.bluewin.ch/lbugnion Support children in Calcutta: http://www.calcutta-espoir.ch
Lauren
I get a "The page cannot be displayed" (HTTP500) error - I am running this
on my ISP server if that makes a difference?
All I have altered is to replace "d:\\temp\\test.txt" with "text.asp" (all
files in the root of my webspace)
Stumpy
"Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_SPAM.ch> wrote in
message news:bm**********@rex.ip-plus.net... Hi,
StumpY wrote:
Hi Laurent,
a small example would be absolutely blinding :)
Cheers for your help
Stumpy
Here is a very simple example. You can modify the table layout in the line 24 and following.
HTH,
Laurent
---------------------------- <%@Language=JavaScript %>
<HTML> <HEAD> <TITLE>GalaSoft</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF">
<%
var NAME_CSV_FILE = "d:\\temp\\test.txt";
var fso = Server.CreateObject( "Scripting.FileSystemObject" );
if ( !fso.FileExists( NAME_CSV_FILE ) ) { Response.Write( "The file doesn't exist" ); } else { // 1 = ForReading var fl = fso.OpenTextFile( NAME_CSV_FILE, 1 );
var strTable = "<TABLE BORDER='1'>\n";
while ( !fl.AtEndOfStream ) { var strLine = fl.ReadLine(); var astrLine = strLine.split( ',' );
// Remove "" from fields var strDate = astrLine[0].substring( 1, astrLine[0].length - 1 ); var strTitle = astrLine[1].substring( 1, astrLine[1].length - 1 ); var strArticle = astrLine[2].substring( 1, astrLine[2].length - 1 );
var strTableRow = "<TR>\n" + "<TD>" + strDate + "</TD>\n" + "<TD>" + strTitle + "</TD>\n" + "<TD>" + strArticle + "</TD>\n" + "</TR>\n";
strTable += strTableRow; }
strTable += "</TABLE>\n";
Response.Write( strTable ); }
%>
</BODY> </HTML>
-- Laurent Bugnion, GalaSoft Webdesign, Java, javascript: http://www.galasoft-LB.ch Private/Malaysia: http://mypage.bluewin.ch/lbugnion Support children in Calcutta: http://www.calcutta-espoir.ch
Hi,
StumpY wrote: Lauren I get a "The page cannot be displayed" (HTTP500) error - I am running this on my ISP server if that makes a difference? All I have altered is to replace "d:\\temp\\test.txt" with "text.asp" (all files in the root of my webspace)
Stumpy
Are you sure that your ISP supports ASP?
Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript : http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Yep - would the server object be too much of a security risk to run on the
ISP server or is this a common practice?
Stumpy
"Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_SPAM.ch> wrote in
message news:3f**********@news.bluewin.ch... Hi,
StumpY wrote: Lauren I get a "The page cannot be displayed" (HTTP500) error - I am running
this on my ISP server if that makes a difference? All I have altered is to replace "d:\\temp\\test.txt" with "text.asp"
(all files in the root of my webspace)
Stumpy
Are you sure that your ISP supports ASP?
Laurent -- Laurent Bugnion, GalaSoft Webdesign, Java, javascript: http://www.galasoft-LB.ch Private/Malaysia: http://mypage.bluewin.ch/lbugnion Support children in Calcutta: http://www.calcutta-espoir.ch
Hi,
StumpY wrote: Yep - would the server object be too much of a security risk to run on the ISP server or is this a common practice?
Stumpy
I suggest that you discuss this with your ISP. On Windows servers (on
others too), it's possible to set pretty much any security restriction
on files and directories. To get access to files, the server must be
registered as a user for the directory the file is in. Without feedback
from your ISP, it's pretty much a wild guess.
Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript : http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Hi Laurent,
just got the following from my ISP - any help?
Cheers,
StumpY
FileSystemObject
Description
Provides access to a computer's file system.
Syntax
Scripting.FileSystemObject
Remarks
The following code illustrates how the FileSystemObject is used to
return a TextStream object that can be read from or written to:
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\testfile.txt", True)
a.WriteLine("This is a test.")
a.Close
In the code shown above, the CreateObject function returns the
FileSystemObject (fs). The CreateTextFile method then creates the file as a
TextStream object (a), and the WriteLine method writes a line of text to the
created text file. The Close method flushes the buffer and closes the file.
"Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_SPAM.ch> wrote in
message news:3f**********@news.bluewin.ch... Hi,
StumpY wrote:
Yep - would the server object be too much of a security risk to run on
the ISP server or is this a common practice?
Stumpy
I suggest that you discuss this with your ISP. On Windows servers (on others too), it's possible to set pretty much any security restriction on files and directories. To get access to files, the server must be registered as a user for the directory the file is in. Without feedback from your ISP, it's pretty much a wild guess.
Laurent -- Laurent Bugnion, GalaSoft Webdesign, Java, javascript: http://www.galasoft-LB.ch Private/Malaysia: http://mypage.bluewin.ch/lbugnion Support children in Calcutta: http://www.calcutta-espoir.ch This discussion thread is closed Replies have been disabled for this discussion. Similar topics
12 posts
views
Thread by Pete..... |
last post: by
|
5 posts
views
Thread by NK |
last post: by
|
1 post
views
Thread by teknowbabble |
last post: by
|
6 posts
views
Thread by martin |
last post: by
|
5 posts
views
Thread by John Bradley |
last post: by
| |
6 posts
views
Thread by shivavrata |
last post: by
|
5 posts
views
Thread by Orv |
last post: by
| | | | | | | | | | |