Dynamically Creating Files with Individual Names

Discussion in 'ASP.NET / ASP.NET Core' started by Karen, Jul 26, 2005.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hi again!

    I'm currently entrenched in trying to figure out how to make my application page write to a new format. Right now, it's writing to a .TXT file. My question, however, has to do with the name of the file that's created when the user clicks "Submit".

    Right now, anyone who fills out the form and clicks the "Submit" button has their info written to a .TXT file that is always named "application.TXT". I'm using the code:




    Dim attachment As New System.Web.Mail.MailAttachment(Server.MapPath("application.txt"))


    I'm wondering if there is a way to create the file name based on information they've filled out in the form. I've come across a situation where we can't use the same file name every time...Each file name that is generated needs to be unique. Anybody know how this can be done? It would also be good to know how I could generate that file name with auto-incrementing numbers too, if it's possible. I'd love the file name to be something like: first initial, last name, auto-incrementing number. It would look like this:


    jsmith0001.fnm


    As always, all help is very appreciated!


    ~Steph
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    what about using a GUID? .NET has a built in function to generate a unique string

    System.GUID.NewGuid().ToString()

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. Bruce

    Bruce DiscountASP.NET Staff

    well.. you have to create the file and put the content into it first.

    System.GUID.NewGuid().ToString() just give you a unique string.

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  4. Thanks Bruce!


    That seems like a good idea for me to pursue. How would I integrate that into my current code? In other words, how do I put that code into my string to create a file name?


    Would this work?


    Dim filename As New System.GUID.NewGuid().ToString()


    Dim attachment As New System.Web.Mail.MailAttachment(Server.MapPath(filename.fnm))


    In all my reading, I've not run across information about the GUID before....


    ~Steph
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page