Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Creating files
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Creating files

 Post Reply Post Reply Page  12>
Author
Davej2k View Drop Down
Newbie
Newbie


Joined: 20 April 2004
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote Davej2k Quote  Post ReplyReply Direct Link To This Post Topic: Creating files
    Posted: 23 April 2004 at 11:56am

Hi there,

I'm having a bit of trouble looking for a script to create a txt file in asp.

Basically I am runing a database to update the news feature on my site, but each actually story comes from a text file rarther than a pure line of text in from the database. So what I require is a script which allows me to type a story into a text box and save it to a folder (e.g. http://www.mynewssite.co.uk/stories/) with a unique file name prferably one that is automatically generated using the day's date or something similar. But one where a text box is used to enter the file name would work just aswell.

Any help would be great, cheers guys.

Dave

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 23 April 2004 at 12:27pm
Google for 'FSO in classic asp' or try this http://www.asptutorial.info/learn/OpenReadCreate-files.asp
Back to Top
Davej2k View Drop Down
Newbie
Newbie


Joined: 20 April 2004
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote Davej2k Quote  Post ReplyReply Direct Link To This Post Posted: 23 April 2004 at 1:29pm

Thanks for the link...

the only problem I have is each file needs to have a different name. e.g. news_story1.txt news_story2.txt etc...

The one's on those examples all write to a preset file.

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 23 April 2004 at 2:25pm
For the code below it will create the file then write to it


<%
thetext="Write this text in the file"

Set fs = CreateObject("Scripting.FileSystemObject")

Set wfile = fs.CreateTextFile("c:\Mydir\myfile.txt", True)
wfile.Write (thetext)

wfile.close
Set wfile=nothing
Set fs=nothing

response.write("Text created")
%>



Back to Top
Semikolon View Drop Down
Senior Member
Senior Member


Joined: 09 September 2003
Location: Norway
Status: Offline
Points: 1718
Post Options Post Options   Thanks (0) Thanks(0)   Quote Semikolon Quote  Post ReplyReply Direct Link To This Post Posted: 23 April 2004 at 3:38pm
replace "c:\Mydir\myfile.txt" with a variable were you have placed the file name
Back to Top
Davej2k View Drop Down
Newbie
Newbie


Joined: 20 April 2004
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote Davej2k Quote  Post ReplyReply Direct Link To This Post Posted: 23 April 2004 at 6:00pm
Sounds straight forward but is there a line of code that will do this as I don't want to have to be changing that line everytime I want to start a new file.
Back to Top
Semikolon View Drop Down
Senior Member
Senior Member


Joined: 09 September 2003
Location: Norway
Status: Offline
Points: 1718
Post Options Post Options   Thanks (0) Thanks(0)   Quote Semikolon Quote  Post ReplyReply Direct Link To This Post Posted: 23 April 2004 at 6:07pm
make a form field called for example filename and place the value of that into a variable called for example strFileName and Replace "c:\Mydir\myfile.txt" with strFileName

to get the value of a field use Request.Form("fieldname")
Back to Top
Davej2k View Drop Down
Newbie
Newbie


Joined: 20 April 2004
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote Davej2k Quote  Post ReplyReply Direct Link To This Post Posted: 23 April 2004 at 6:33pm

OK so far here's what I have an initial page which contains the form fields filename and story and posts to this page:

<%

Dim strfilename

Dim Story

filename = Request.Form("fieldname")

Story = Request.Form("story")

Set fs = CreateObject("Scripting.FileSystemObject")

Set wfile = fs.CreateTextFile("strfilename", True)

wfile.Write (Story)

wfile.close

Set wfile=nothing

Set fs=nothing

response.write("Text created")

%>

At the moment I'm getting an error saying permission denied probably to the folder I'm trying to add the file to. Can you point me in the way of any other faults. I'm new to asp BTW and really appreciate your help!

Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.