Re: Creating ASPX dynamically and saving as single file .ASPX

Discussion in 'ASP .Net' started by Nathan Sokalski, Jan 15, 2009.

  1. Have you ever worked with creating/writing text files from code? This is all
    you really need to do, since an *.aspx file is just a text file with an
    extension of aspx. Here are two simple examples:


    To create a new file or overwrite an existing file:

    Dim texttestwriter As StreamWriter =
    File.CreateText(Server.MapPath("TextTest.txt"))
    Dim writetime As Date = Date.Now
    texttestwriter.WriteLine("This line was written at {0} {1}",
    writetime.ToShortDateString(), writetime.ToLongTimeString())
    texttestwriter.Close()


    To append text to an existing file:

    Dim texttestwriter As StreamWriter =
    File.AppendText(Server.MapPath("TextTest.txt"))
    Dim writetime As Date = Date.Now
    texttestwriter.WriteLine("This line was written at {0} {1}",
    writetime.ToShortDateString(), writetime.ToLongTimeString())
    texttestwriter.Close()


    The only difference between the two is that one uses File.CreateText and the
    other uses File.AppendText. There are several overloads of the WriteLine
    method (see the documentation for the other overloads). Hopefully this
    helps. Good Luck!
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "davebullet" <u48867@uwe> wrote in message news:9031ddd5f35f9@uwe...
    > Hi there,
    >
    > I want to be able to dynamically create a new ASPX in code and save this
    > to a
    > aspx file to another website.
    >
    > I don't want to save the rendered HTML from the ASPX page created. I want
    > to
    > save the ASPX page definition itself (the .aspx version of the in memory
    > created page).
    >
    > Creating the page in code is easy, but how do I persist it as an ASPX
    > file?
    >
    > Thanks,
    > David.
    >
     
    Nathan Sokalski, Jan 15, 2009
    #1
    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. John Kandell
    Replies:
    4
    Views:
    4,169
    eeebop
    Dec 10, 2004
  2. Luis Esteban Valencia
    Replies:
    0
    Views:
    2,519
    Luis Esteban Valencia
    Jan 6, 2005
  3. oyster
    Replies:
    0
    Views:
    482
    oyster
    Oct 21, 2008
  4. Anthony Jones
    Replies:
    1
    Views:
    538
    Anthony Jones
    Jan 16, 2009
  5. Lovely Angel For You

    Saving Images While Saving ASP Pages !

    Lovely Angel For You, Oct 2, 2003, in forum: ASP General
    Replies:
    1
    Views:
    210
    Curt_C [MVP]
    Oct 3, 2003
Loading...

Share This Page