Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Altering File Names On Download

Altering File Names On Download

Scheduled Pinned Locked Moved ASP.NET
questiondatabasewindows-adminlounge
10 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sam Heller
    wrote on last edited by
    #1

    I have an upload section to a site I have built where users can upload whatever files they want. Upon upload a new name is created using a randon string generator and saved into one folder. The new name and the original name are then stored in a database. Simple The files are then displayed in a table on a page where the name of the link is the original name and the randon string name is the absolute link to the real file. This works fine but the file once downloaded comes with the random string as it's file name. How can I alter the name of the file back to it's original name when selected for download? I don't have access to IIS so this needs to be done in code on the fly? Many Thanks

    V 1 Reply Last reply
    0
    • S Sam Heller

      I have an upload section to a site I have built where users can upload whatever files they want. Upon upload a new name is created using a randon string generator and saved into one folder. The new name and the original name are then stored in a database. Simple The files are then displayed in a table on a page where the name of the link is the original name and the randon string name is the absolute link to the real file. This works fine but the file once downloaded comes with the random string as it's file name. How can I alter the name of the file back to it's original name when selected for download? I don't have access to IIS so this needs to be done in code on the fly? Many Thanks

      V Offline
      V Offline
      Vasudevan Deepak Kumar
      wrote on last edited by
      #2

      Can't you set the new name in the Content-Disposition header? Check out a quick example here: http://support.microsoft.com/kb/260519[^]

      Vasudevan Deepak Kumar Personal Homepage
      Tech Gossips
      A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

      S 1 Reply Last reply
      0
      • V Vasudevan Deepak Kumar

        Can't you set the new name in the Content-Disposition header? Check out a quick example here: http://support.microsoft.com/kb/260519[^]

        Vasudevan Deepak Kumar Personal Homepage
        Tech Gossips
        A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

        S Offline
        S Offline
        Sam Heller
        wrote on last edited by
        #3

        Yes I guess this is an option. This is exactly the same code that I use to output an Active Report to the user. It does of course invoke a postback though and additional processing. Can you see any issue with this? Any other options? Presumably I would need to load the file in my code into say a memory stream?

        V 1 Reply Last reply
        0
        • S Sam Heller

          Yes I guess this is an option. This is exactly the same code that I use to output an Active Report to the user. It does of course invoke a postback though and additional processing. Can you see any issue with this? Any other options? Presumably I would need to load the file in my code into say a memory stream?

          V Offline
          V Offline
          Vasudevan Deepak Kumar
          wrote on last edited by
          #4

          Sam Heller wrote:

          I would need to load the file in my code into say a memory stream

          How about response.writefile or response.transmitfile rather?

          Vasudevan Deepak Kumar Personal Homepage
          Tech Gossips
          A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

          S 1 Reply Last reply
          0
          • V Vasudevan Deepak Kumar

            Sam Heller wrote:

            I would need to load the file in my code into say a memory stream

            How about response.writefile or response.transmitfile rather?

            Vasudevan Deepak Kumar Personal Homepage
            Tech Gossips
            A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

            S Offline
            S Offline
            Sam Heller
            wrote on last edited by
            #5

            Hmm the original method you suggested seems to work fine. The only problem is I won't be able to do this from inside an update panel. Any suggestions?

            S V 2 Replies Last reply
            0
            • S Sam Heller

              Hmm the original method you suggested seems to work fine. The only problem is I won't be able to do this from inside an update panel. Any suggestions?

              S Offline
              S Offline
              Sam Heller
              wrote on last edited by
              #6

              Further to this the content disposition method can't handle white space in the file name. I have been forced to run a quick replace to turn them all into underscores. Not ideal but I can live with it? Any suggestions to allow whitespace?

              V 1 Reply Last reply
              0
              • S Sam Heller

                Further to this the content disposition method can't handle white space in the file name. I have been forced to run a quick replace to turn them all into underscores. Not ideal but I can live with it? Any suggestions to allow whitespace?

                V Offline
                V Offline
                Vasudevan Deepak Kumar
                wrote on last edited by
                #7

                Sam Heller wrote:

                the content disposition method can't handle white space in the file name

                No. I think it takes it. Did you try escaping them and sending it to the web browser?

                Vasudevan Deepak Kumar Personal Homepage
                Tech Gossips
                A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

                S 1 Reply Last reply
                0
                • S Sam Heller

                  Hmm the original method you suggested seems to work fine. The only problem is I won't be able to do this from inside an update panel. Any suggestions?

                  V Offline
                  V Offline
                  Vasudevan Deepak Kumar
                  wrote on last edited by
                  #8

                  Sam Heller wrote:

                  update panel

                  AJAX control?

                  Vasudevan Deepak Kumar Personal Homepage
                  Tech Gossips
                  A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

                  S 1 Reply Last reply
                  0
                  • V Vasudevan Deepak Kumar

                    Sam Heller wrote:

                    update panel

                    AJAX control?

                    Vasudevan Deepak Kumar Personal Homepage
                    Tech Gossips
                    A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

                    S Offline
                    S Offline
                    Sam Heller
                    wrote on last edited by
                    #9

                    Yeah the ajax control known as the updatepanel. It doesn't allow the write though and errors.

                    1 Reply Last reply
                    0
                    • V Vasudevan Deepak Kumar

                      Sam Heller wrote:

                      the content disposition method can't handle white space in the file name

                      No. I think it takes it. Did you try escaping them and sending it to the web browser?

                      Vasudevan Deepak Kumar Personal Homepage
                      Tech Gossips
                      A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

                      S Offline
                      S Offline
                      Sam Heller
                      wrote on last edited by
                      #10

                      How would you escape the spaces in this way. If I have; Response.AddHeader("content-disposition", "attachment; filename=" + ThisFile.FriendlyName) Thanks

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups