How to create a file in ASP?

7 replies
I have done some reasearch on how to create files
in ASP and found this script:
<%
thetext="Write this text in the file"

Set fs = CreateObject("Scripting.FileSystemObject")
Set wfile = fs.CreateTextFile("myfile.txt", True)
wfile.Write (thetext)
wfile.close
Set wfile=nothing
Set fs=nothing response.write("Text created")
%>

then I created an asp file containing only this script, named it
"create" and uploaded it on one account on one asp-supporting
free host. Then I tried to open that file using my IE6 browser
and received an error message. Then I checked my file manager
(on that free account) and saw that a new file (''myfile.txt") was
not created. I think I am missing something here. Can anyone,
please, explain to me what should I do in order to create files in ASP?
#asp #create #file
  • Profile picture of the author sunconsultancy
    Banned
    [DELETED]
    {{ DiscussionBoard.errors[342962].message }}
    • Are you sure you posted this in the right thread? It seems to me that you were answering some other question, but not mine.
      {{ DiscussionBoard.errors[343035].message }}
      • I also tried this script (I took it from here):

        <%
        dim fs,f
        set fs=Server.CreateObject("Scripting.FileSystemObject ")
        set f=fs.OpenTextFile(Server.MapPath("testread.txt"),8 ,true)
        f.WriteLine("This text will be added to the end of file")
        f.Close
        set f=Nothing
        set fs=Nothing
        %>


        I copied this script into an asp file that I named "experiment"
        (experiment.asp) and placed that file into the main folder on my
        free account that I had previously opened on a remote
        asp-supported free server.

        As far as I understand, since the last parameter in
        f=fs.OpenTextFile(Server.MapPath("testread.txt"),8 ,true)
        is "true", the new file (testread.txt) must be created in the same
        folder. However, after I created experiment.asp and tried to open
        it with my web-browser (IE 6), the new file wasn't created.

        Instead, I got this message:


        Server objecterror 'ASP 0177 : 800401f3'
        Server.CreateObject Failed
        /experiment.asp, line 5
        800401f3

        Why is it so?
        {{ DiscussionBoard.errors[345036].message }}
        • Profile picture of the author rachusrs2
          Because of virus threat many servers wont allow you
          to use scripting objects like creating files & folders.
          which your error seems to indicate.

          why not go in for PHP its free and supported by
          almost all webhosts and u have a large community
          to get u through if any problem should arise
          {{ DiscussionBoard.errors[346268].message }}
          • Originally Posted by rachusrs2 View Post

            why not go in for PHP its free and supported by
            almost all webhosts and u have a large community
            to get u through if any problem should arise
            Well, I tried doing it in PHP before (click on the name of this thread
            in order to see it:
            "Is there any web-page copying command in PHP" ), but I
            stumbled on a similar problem: the allow_url_fopen is not allowed on
            free PHP servers.
            {{ DiscussionBoard.errors[347752].message }}
  • Profile picture of the author ofir
    Banned
    I don't really know ASP.
    But try to change the folder's permissions.
    "CHMOD" the folder to 0777.
    and also check if there is any command in ASP to chmod files,
    because maybe you need to chmod the new file that created before writing something in it.
    {{ DiscussionBoard.errors[345172].message }}
    • ofir wrote:
      ""CHMOD" the folder to 0777.
      and also check if there is any command in ASP to chmod files"

      - how do I do it?
      {{ DiscussionBoard.errors[345199].message }}
  • Thanks for telling me that - finally I know the reason.
    {{ DiscussionBoard.errors[347277].message }}

Trending Topics