Create a file with FileSystemObject

Discussion in 'ASP General' started by jessie, Oct 31, 2003.

  1. jessie

    jessie Guest

    This my code for practice:

    <html>
    <body>
    <%
    Response.Write("6 ")
    dim fs,fname
    set fs=CreateObject("Scripting.FileSystemObject")
    set fname=fs.CreateTextFile("f:\test.txt")
    fname.WriteLine("Hello World!")
    fname.Close
    set fname=nothing
    set fs=nothing
    %>
    </body>
    </html>

    but I couldn't create the text file at all with no error warning.
    How can I do this?

    Thanks a lot.
     
    jessie, Oct 31, 2003
    #1
    1. Advertising

  2. "jessie" <> schrieb im Newsbeitrag
    news:Xns94257BC3C2408allywzcnet@207.46.248.16...
    > This my code for practice:
    >
    > snipped
    >
    > but I couldn't create the text file at all with no error warning.
    > How can I do this?


    What does the error message say?

    The CreateTextFile might fail, because the file already exists (and the
    overwrite parameter is not given). Or the CreateTextFile might fail, because
    the account does not have enough access rights to the directory.

    Michael G. Schneider
     
    Michael G. Schneider, Oct 31, 2003
    #2
    1. Advertising

  3. jessie

    jessie Guest


    > What does the error message say?
    >
    > The CreateTextFile might fail, because the file already exists (and
    > the overwrite parameter is not given). Or the CreateTextFile might
    > fail, because the account does not have enough access rights to the
    > directory.



    There is no error message. It is running and nothing comes out.
    the overwrite parameter is ture for default, isn't it?
    How to give it the right to access to the directory?
    Thanks.
     
    jessie, Oct 31, 2003
    #3
  4. jessie

    Rob Meade Guest

    "jessie" wrote ...

    > There is no error message.


    You could always try putting some

    Response.Write "I got to this step"
    Response.Write "Now I am at this step"

    etc etc, to see where it gets to before it fails.

    You could also check your browser settings to see if you have friendly
    errors turned on (if so try turning it off).

    > the overwrite parameter is ture for default, isn't it?


    I believe so, yes.

    > How to give it the right to access to the directory?


    Browse through to the directory you are trying to save the file in,
    right-click on it, left-click on properties.
    Left-click the security tab, see if the 'IUSR_<computer_name>' account is
    listed, if not - try adding it and give it everything but full access (or
    give it full access but just for now to test etc).

    Now rerun your code - you might want to stick a response.write at the end of
    your code to so that you know if its got that far...

    Just one question - you showed the F drive above - this will sound daft -
    but its not your CD rom drive is it?

    Regards

    Rob
     
    Rob Meade, Oct 31, 2003
    #4
  5. "jessie" <> schrieb im Newsbeitrag
    news:Xns94258774CFC02allywzcnet@207.46.248.16...
    >
    > > What does the error message say?
    > >
    > > The CreateTextFile might fail, because the file already exists (and
    > > the overwrite parameter is not given). Or the CreateTextFile might
    > > fail, because the account does not have enough access rights to the
    > > directory.

    >
    >
    > There is no error message. It is running and nothing comes out.
    > the overwrite parameter is ture for default, isn't it?
    > How to give it the right to access to the directory?


    You should look up the CreateTextFile method. I believe, the overwrite is
    False by default. The ASP page will be executed under a certain account. If
    you do nothing special, this should be the IIS_machine account. This account
    needs the access rights to the directory on the IIS Server. For setting the
    access right, navigate to the folder, right click, properties, security.

    Michael G. Schneider
     
    Michael G. Schneider, Oct 31, 2003
    #5
  6. jessie

    jessie Guest


    > You could always try putting some
    >
    > Response.Write "I got to this step"
    > Response.Write "Now I am at this step"

    I did this, and I found the problem occurs in the CreateTextFile. If I cut
    this line, it is Ok.

    > Just one question - you showed the F drive above - this will sound
    > daft - but its not your CD rom drive is it?

    It is not my CD rom.
     
    jessie, Oct 31, 2003
    #6
  7. www.aspfaq.com/2180



    "jessie" <> wrote in message
    news:Xns9425930EA9FC7allywzcnet@207.46.248.16...
    >
    > > You could always try putting some
    > >
    > > Response.Write "I got to this step"
    > > Response.Write "Now I am at this step"

    > I did this, and I found the problem occurs in the CreateTextFile. If I cut
    > this line, it is Ok.
    >
    > > Just one question - you showed the F drive above - this will sound
    > > daft - but its not your CD rom drive is it?

    > It is not my CD rom.
    >
     
    Aaron Bertrand - MVP, Oct 31, 2003
    #7
  8. jessie

    Bob Barrows Guest

    jessie wrote:
    >> What does the error message say?
    >>
    >> The CreateTextFile might fail, because the file already exists (and
    >> the overwrite parameter is not given). Or the CreateTextFile might
    >> fail, because the account does not have enough access rights to the
    >> directory.

    >
    >
    > There is no error message. It is running and nothing comes out.
    > the overwrite parameter is ture for default, isn't it?
    > How to give it the right to access to the directory?
    > Thanks.


    Could this be the problem?
    http://www.aspfaq.com/show.asp?id=2180

    Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows, Oct 31, 2003
    #8
  9. jessie

    jessie Guest

    jessie, Oct 31, 2003
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pedro Bautista
    Replies:
    0
    Views:
    541
    Pedro Bautista
    Aug 29, 2003
  2. Roger Withnell

    Deleting a file with the FileSystemObject

    Roger Withnell, Jul 14, 2003, in forum: ASP General
    Replies:
    3
    Views:
    94
    Roger Withnell
    Jul 14, 2003
  3. Lin Ma
    Replies:
    2
    Views:
    330
    Lin Ma
    Jun 10, 2004
  4. Astra
    Replies:
    1
    Views:
    461
    Patrice
    Dec 13, 2005
  5. Astra
    Replies:
    4
    Views:
    458
    Laphan
    Dec 20, 2005
Loading...

Share This Page