Create file client side with VB.NET and ASP.NET

Discussion in 'ASP .Net' started by Russ Green, May 19, 2005.

  1. Russ Green

    Russ Green Guest

    I need help writing a method to create a simple text file. I want that file
    to be saved to a local drive (client side of my asp.net app). The filename
    will always be the same "license.txt" but the content will be different for
    each user. I don't really want to create the file on my server and them have
    them downloaded it. I would much rather use a stringbuilder and the save the
    contents of the stringbuilder to the users local drive (propted of course).

    TIA

    Russ
     
    Russ Green, May 19, 2005
    #1
    1. Advertisements

  2. The classic download/upload example:

    http://www.ondotnet.com/pub/a/dotnet/2002/04/01/asp.html

    Instead of WriteFile, just Write the builder.ToString()
     
    Craig Deelsnyder, May 19, 2005
    #2
    1. Advertisements

  3. Russ Green

    Patrice Guest

    If this is to raise the "save file" prompt, try :
    http://support.microsoft.com/kb/260519/en-us

    Else tell use what is the exact point on which you need help...

    Of course once the file is saved you won't be able to access it (don't
    really know if it will be usefull then...)

    Patrice
     
    Patrice, May 19, 2005
    #3
  4. Russ Green

    Cor Ligthert Guest

    Russ,

    You can not write even a simple file on the userside with ASPNET with normal
    security settings.

    However you can add information to the cookies which are normally (in non
    cookieless mode) set on the clients computer. You can reread that as well.
    (don't forget to set the expire date.

    I hope this helps,

    Cor
     
    Cor Ligthert, May 19, 2005
    #4
  5. Russ Green

    Russ Green Guest

    I'm not trying to write the file directly to the users hard disk. What I
    want to do is allow them the dow2nload the file when they click a link. What
    I don't want, is to generate that file physically on my server. II would
    like, if possible, to generate that file in memory and then present the user
    with the standard download dialog so they can choose to download the file on
    their system.
     
    Russ Green, May 19, 2005
    #5
  6. Russ Green

    Russ Green Guest

    Thanks,

    I currently have this little test I'm working on. It doesn't make a file and
    present the user with the download dialog it just displays the sb string in
    the web browser.

    Help!!!

    Private Sub Page_Load (ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    ' Create a stringbuilder to hold the text to be sent
    Dim sb As New System.Text.StringBuilder

    ' Add the text content to the stringbuilder
    sb.Append("line 1" & vbcrLf)
    sb.Append("line 2" & vbcrLf)

    'Set the appropriate ContentType.
    Response.ContentType = "text/plain"

    ' Add a header telling the browser
    ' to expect an attachment and give it the
    ' name of the attachment
    Dim filename As String = "license.lic"
    Response.AddHeader("Content-Disposition", _
    "attachment; filename=""" & filename & """")

    'Write the file's content from the stringbuilder
    ' directly to the HTTP output stream.
    Response.Write(sb.ToString)
    Response.End()
    End Sub
     
    Russ Green, May 19, 2005
    #6
  7. Russ Green

    Cor Ligthert Guest

    Russ,

    Sorry, however why do you do it in an other way as everybody else.
    Everybody shows that page and than the user can decide himself to save it or
    not. What is the advantage from the method you want to do.

    It seems to me especially in the EU a less juridistic good way

    Just my thought,

    Cor
     
    Cor Ligthert, May 19, 2005
    #7
  8. Russ Green

    Russ Green Guest

    Well what I'm actually trying to do is generate a license file for a user to
    download. The content will be unique to any particular user. I want that
    user to login to my site. Click a link and be presented with a dialog for
    them to download their very own unique license file. I've seen it done
    before.
     
    Russ Green, May 19, 2005
    #8
  9. Russ Green

    Cor Ligthert Guest

    Russ,

    Why not create an unique page for them.
    They have a save as button on their browser (there is as well javascript to
    do that).

    Cor
     
    Cor Ligthert, May 19, 2005
    #9
  10. Russ Green

    Patrice Guest

    In case you missed my message :
    http://support.microsoft.com/kb/260519/en-us shows how to raise the "save
    as" box.

    Addtionaly use just Response.Write to write down the file content (client
    side the browser doesn't know where the content comes, it just see incoming
    bytes). The article is for ASP but applies as well to ASP.NET...

    Patrice
     
    Patrice, May 19, 2005
    #10
  11. Russ Green

    Russ Green Guest

    This code has just done exactly what I want it to on my PC at home.
    Brilliant!! When I tried it in work earlier it wasn't working. Why? What
    could stop it working on some browsers?

    Private Sub Page_Load (ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load

    ' Create a stringbuilder to hold the text to be sent

    Dim sb As New System.Text.StringBuilder

    ' Add the text content to the stringbuilder

    sb.Append("<?xml version=1.0 encoding=UTF-8 ?>" & vbcrLf)

    sb.Append("<configuration>" & vbcrLf)

    sb.Append("</configuration>" & vbcrLf)

    ' Set the appropriate ContentType.

    Response.ContentType = "text/xml"

    ' Add a header telling the browser

    ' to expect an attachment and give it the

    ' name of the attachment

    Dim filename As String = "license.xml"

    Response.AddHeader("Content-Disposition", _

    "attachment; filename=""" & filename & """")

    ' Write the file's content from the stringbuilder

    ' directly to the HTTP output stream.

    Response.Write(sb.ToString)

    Response.End()

    End Sub
     
    Russ Green, May 19, 2005
    #11
  12. Russ Green

    Patrice Guest

    This article list that ie 4.01 is know to have problems with this.

    How does it fail ? (it displays the XML ?)

    IMO a browser could perhaps just check the content type and handle this
    regardless of the content-disposition header... I would try without with the
    content-type or with a fictionous content type. I would try also a different
    extension for the filename (just random tries to try to undestand what is
    the element that causes the problem).

    Patrice

    --
     
    Patrice, May 19, 2005
    #12
  13. Russ Green

    thegreatone

    Joined:
    Feb 7, 2012
    Messages:
    1
    Likes Received:
    0
    create file on client side

    hello guys,
    i am quite new to all this ASP.NET so bear with me,
    how can i create the following process:

    From my ASP page, when a user clicks a button, a file is generated on the server-side and then transmitted to the users hard disk and stored in a specified directory that i will have specified in code.

    Thank you in advance, really appreciate your helo
     
    thegreatone, Feb 7, 2012
    #13
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.