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. Other Discussions
  3. The Weird and The Wonderful
  4. Take care of your TEMP folder!

Take care of your TEMP folder!

Scheduled Pinned Locked Moved The Weird and The Wonderful
helpcomgraphicssysadmintools
10 Posts 7 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.
  • B Offline
    B Offline
    Bernhard Hiller
    wrote on last edited by
    #1

    The ghosts of the past won't let me rest. My former boss informed me that our project web page "was broken. At least, it is not listed as a malware site on Google". Well, last thing happened to us last year after a hacker attack (see http://www.codeproject.com/Messages/4323984/Analysing-an-obfuscated-malware-script.aspx[^]). Since that project was my best piece of work (seriously, not in the satirical meaning of the rest of this post, and despite the code shown below), I immediately looked into it: the home page loaded smoothly. Nothing wrong. The next pages also. So, what was wrong? I tried an aspx page. Worked. Next aspx page, and here it was:

    Error: Access violation. File exists. at
    strFileName = System.IO.Path.GetTempFileName

    The page creates an image dynamically, based on user input. The image is written into Graphics folder of the web site. After the web site was moved to a different server, the clean-up process for that folder failed due to a lack of access rights. But that was long ago. I looked into that folder, and it was empty. But wait, that line mentioned in the error message does something different! Before the temporary image file is created, I ask Windows to give me a file name. I created such a superb function for that purpose:

    Public Function getTempFileName(Optional ByVal Extension As String = "tmp") As String
    Dim strFileName As String

    'system temp file name
    strFileName = System.IO.Path.GetTempFileName
    
    'file name only
    strFileName = strFileName.Substring(System.IO.Path.GetTempPath.Length)
    
    'default extension is "tmp", if we want a different one, we must exchange it
    If Extension <> "tmp" Then
        strFileName = strFileName.Substring(0, strFileName.Length - 3) & Extension
    End If
    
    'done
    Return strFileName
    

    End Function

    Overwhelmed by the beauty of this piece of code (it will surely be honored as the proper solution to that problem in many VB and aspx fora throughout the web soon), you'll likely not see how this function can fail. Also I had to take a look into Microsoft's documentation: Not only does System.IO.Path.GetTempFileName return the full path for a temporary file, it does al

    A P B Richard DeemingR 5 Replies Last reply
    0
    • B Bernhard Hiller

      The ghosts of the past won't let me rest. My former boss informed me that our project web page "was broken. At least, it is not listed as a malware site on Google". Well, last thing happened to us last year after a hacker attack (see http://www.codeproject.com/Messages/4323984/Analysing-an-obfuscated-malware-script.aspx[^]). Since that project was my best piece of work (seriously, not in the satirical meaning of the rest of this post, and despite the code shown below), I immediately looked into it: the home page loaded smoothly. Nothing wrong. The next pages also. So, what was wrong? I tried an aspx page. Worked. Next aspx page, and here it was:

      Error: Access violation. File exists. at
      strFileName = System.IO.Path.GetTempFileName

      The page creates an image dynamically, based on user input. The image is written into Graphics folder of the web site. After the web site was moved to a different server, the clean-up process for that folder failed due to a lack of access rights. But that was long ago. I looked into that folder, and it was empty. But wait, that line mentioned in the error message does something different! Before the temporary image file is created, I ask Windows to give me a file name. I created such a superb function for that purpose:

      Public Function getTempFileName(Optional ByVal Extension As String = "tmp") As String
      Dim strFileName As String

      'system temp file name
      strFileName = System.IO.Path.GetTempFileName
      
      'file name only
      strFileName = strFileName.Substring(System.IO.Path.GetTempPath.Length)
      
      'default extension is "tmp", if we want a different one, we must exchange it
      If Extension <> "tmp" Then
          strFileName = strFileName.Substring(0, strFileName.Length - 3) & Extension
      End If
      
      'done
      Return strFileName
      

      End Function

      Overwhelmed by the beauty of this piece of code (it will surely be honored as the proper solution to that problem in many VB and aspx fora throughout the web soon), you'll likely not see how this function can fail. Also I had to take a look into Microsoft's documentation: Not only does System.IO.Path.GetTempFileName return the full path for a temporary file, it does al

      A Offline
      A Offline
      AlphaDeltaTheta
      wrote on last edited by
      #2

      Oh.. it's considered a standard practice to delete the temp file after use... so, i'll say it's coding fault! Please, no offence :laugh: I don't rely on the get temp file though, I have my own random naming algorithm, kept locked highly in my hard drive with several layers of ultra military grade encryption! ! ;)

      1 Reply Last reply
      0
      • B Bernhard Hiller

        The ghosts of the past won't let me rest. My former boss informed me that our project web page "was broken. At least, it is not listed as a malware site on Google". Well, last thing happened to us last year after a hacker attack (see http://www.codeproject.com/Messages/4323984/Analysing-an-obfuscated-malware-script.aspx[^]). Since that project was my best piece of work (seriously, not in the satirical meaning of the rest of this post, and despite the code shown below), I immediately looked into it: the home page loaded smoothly. Nothing wrong. The next pages also. So, what was wrong? I tried an aspx page. Worked. Next aspx page, and here it was:

        Error: Access violation. File exists. at
        strFileName = System.IO.Path.GetTempFileName

        The page creates an image dynamically, based on user input. The image is written into Graphics folder of the web site. After the web site was moved to a different server, the clean-up process for that folder failed due to a lack of access rights. But that was long ago. I looked into that folder, and it was empty. But wait, that line mentioned in the error message does something different! Before the temporary image file is created, I ask Windows to give me a file name. I created such a superb function for that purpose:

        Public Function getTempFileName(Optional ByVal Extension As String = "tmp") As String
        Dim strFileName As String

        'system temp file name
        strFileName = System.IO.Path.GetTempFileName
        
        'file name only
        strFileName = strFileName.Substring(System.IO.Path.GetTempPath.Length)
        
        'default extension is "tmp", if we want a different one, we must exchange it
        If Extension <> "tmp" Then
            strFileName = strFileName.Substring(0, strFileName.Length - 3) & Extension
        End If
        
        'done
        Return strFileName
        

        End Function

        Overwhelmed by the beauty of this piece of code (it will surely be honored as the proper solution to that problem in many VB and aspx fora throughout the web soon), you'll likely not see how this function can fail. Also I had to take a look into Microsoft's documentation: Not only does System.IO.Path.GetTempFileName return the full path for a temporary file, it does al

        A Offline
        A Offline
        AlphaDeltaTheta
        wrote on last edited by
        #3

        Bernhard Hiller wrote:

        Well, last thing happened to us last year after a hacker attack (see http://www.codeproject.com/Messages/4323984/Analysing-an-obfuscated-malware-script.aspx[^]).

        The hacker has a brilliant idea, i'm thinking to leverage it into a javascript ofuscator! :laugh:

        L 1 Reply Last reply
        0
        • A AlphaDeltaTheta

          Bernhard Hiller wrote:

          Well, last thing happened to us last year after a hacker attack (see http://www.codeproject.com/Messages/4323984/Analysing-an-obfuscated-malware-script.aspx[^]).

          The hacker has a brilliant idea, i'm thinking to leverage it into a javascript ofuscator! :laugh:

          L Offline
          L Offline
          Lutoslaw
          wrote on last edited by
          #4

          Amitosh Swain wrote:

          i'm thinking to leverage it into a javascript ofuscator!

          Uhm, so... the next "hacker's script" will be yours... or maybe this one was! <hides his IP under the desk>

          Greetings - Jacek

          A 1 Reply Last reply
          0
          • B Bernhard Hiller

            The ghosts of the past won't let me rest. My former boss informed me that our project web page "was broken. At least, it is not listed as a malware site on Google". Well, last thing happened to us last year after a hacker attack (see http://www.codeproject.com/Messages/4323984/Analysing-an-obfuscated-malware-script.aspx[^]). Since that project was my best piece of work (seriously, not in the satirical meaning of the rest of this post, and despite the code shown below), I immediately looked into it: the home page loaded smoothly. Nothing wrong. The next pages also. So, what was wrong? I tried an aspx page. Worked. Next aspx page, and here it was:

            Error: Access violation. File exists. at
            strFileName = System.IO.Path.GetTempFileName

            The page creates an image dynamically, based on user input. The image is written into Graphics folder of the web site. After the web site was moved to a different server, the clean-up process for that folder failed due to a lack of access rights. But that was long ago. I looked into that folder, and it was empty. But wait, that line mentioned in the error message does something different! Before the temporary image file is created, I ask Windows to give me a file name. I created such a superb function for that purpose:

            Public Function getTempFileName(Optional ByVal Extension As String = "tmp") As String
            Dim strFileName As String

            'system temp file name
            strFileName = System.IO.Path.GetTempFileName
            
            'file name only
            strFileName = strFileName.Substring(System.IO.Path.GetTempPath.Length)
            
            'default extension is "tmp", if we want a different one, we must exchange it
            If Extension <> "tmp" Then
                strFileName = strFileName.Substring(0, strFileName.Length - 3) & Extension
            End If
            
            'done
            Return strFileName
            

            End Function

            Overwhelmed by the beauty of this piece of code (it will surely be honored as the proper solution to that problem in many VB and aspx fora throughout the web soon), you'll likely not see how this function can fail. Also I had to take a look into Microsoft's documentation: Not only does System.IO.Path.GetTempFileName return the full path for a temporary file, it does al

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            Oh, yuck! Substring! :wtf: system.io.path.getfilenamewithoutextension[^]

            T B 2 Replies Last reply
            0
            • L Lutoslaw

              Amitosh Swain wrote:

              i'm thinking to leverage it into a javascript ofuscator!

              Uhm, so... the next "hacker's script" will be yours... or maybe this one was! <hides his IP under the desk>

              Greetings - Jacek

              A Offline
              A Offline
              AlphaDeltaTheta
              wrote on last edited by
              #6

              Jacek Gajek wrote:

              Uhm, so... the next "hacker's script" will be yours... or maybe this one was

              I'm not that good at breaking anything... anything means anything...

              1 Reply Last reply
              0
              • P PIEBALDconsult

                Oh, yuck! Substring! :wtf: system.io.path.getfilenamewithoutextension[^]

                T Offline
                T Offline
                TnTinMn
                wrote on last edited by
                #7

                Better yet, just use System.IO.Path.ChangeExtension. But making faulty code more readable does seem pointless. ;P

                1 Reply Last reply
                0
                • P PIEBALDconsult

                  Oh, yuck! Substring! :wtf: system.io.path.getfilenamewithoutextension[^]

                  B Offline
                  B Offline
                  Bernhard Hiller
                  wrote on last edited by
                  #8

                  Yeah, two times substring instead of the functions of System.IO.Path - 9 years ago I did not know them. But you see: you'd fix the substrings, not the failure. The beauty of this gem prevents you from really fixing the problem (e.g. strFileName = Guid.NewGuid().ToString() & "." & Extension)

                  1 Reply Last reply
                  0
                  • B Bernhard Hiller

                    The ghosts of the past won't let me rest. My former boss informed me that our project web page "was broken. At least, it is not listed as a malware site on Google". Well, last thing happened to us last year after a hacker attack (see http://www.codeproject.com/Messages/4323984/Analysing-an-obfuscated-malware-script.aspx[^]). Since that project was my best piece of work (seriously, not in the satirical meaning of the rest of this post, and despite the code shown below), I immediately looked into it: the home page loaded smoothly. Nothing wrong. The next pages also. So, what was wrong? I tried an aspx page. Worked. Next aspx page, and here it was:

                    Error: Access violation. File exists. at
                    strFileName = System.IO.Path.GetTempFileName

                    The page creates an image dynamically, based on user input. The image is written into Graphics folder of the web site. After the web site was moved to a different server, the clean-up process for that folder failed due to a lack of access rights. But that was long ago. I looked into that folder, and it was empty. But wait, that line mentioned in the error message does something different! Before the temporary image file is created, I ask Windows to give me a file name. I created such a superb function for that purpose:

                    Public Function getTempFileName(Optional ByVal Extension As String = "tmp") As String
                    Dim strFileName As String

                    'system temp file name
                    strFileName = System.IO.Path.GetTempFileName
                    
                    'file name only
                    strFileName = strFileName.Substring(System.IO.Path.GetTempPath.Length)
                    
                    'default extension is "tmp", if we want a different one, we must exchange it
                    If Extension <> "tmp" Then
                        strFileName = strFileName.Substring(0, strFileName.Length - 3) & Extension
                    End If
                    
                    'done
                    Return strFileName
                    

                    End Function

                    Overwhelmed by the beauty of this piece of code (it will surely be honored as the proper solution to that problem in many VB and aspx fora throughout the web soon), you'll likely not see how this function can fail. Also I had to take a look into Microsoft's documentation: Not only does System.IO.Path.GetTempFileName return the full path for a temporary file, it does al

                    B Offline
                    B Offline
                    BobJanova
                    wrote on last edited by
                    #9

                    This one's a lesson in why reading the documentation can be helpful. GetTempFileName states that it creates the file ... somewhat annoying if you want to create a temporary file with a different name (extension), but I guess their point is that the name doesn't matter as it's only temporary.

                    1 Reply Last reply
                    0
                    • B Bernhard Hiller

                      The ghosts of the past won't let me rest. My former boss informed me that our project web page "was broken. At least, it is not listed as a malware site on Google". Well, last thing happened to us last year after a hacker attack (see http://www.codeproject.com/Messages/4323984/Analysing-an-obfuscated-malware-script.aspx[^]). Since that project was my best piece of work (seriously, not in the satirical meaning of the rest of this post, and despite the code shown below), I immediately looked into it: the home page loaded smoothly. Nothing wrong. The next pages also. So, what was wrong? I tried an aspx page. Worked. Next aspx page, and here it was:

                      Error: Access violation. File exists. at
                      strFileName = System.IO.Path.GetTempFileName

                      The page creates an image dynamically, based on user input. The image is written into Graphics folder of the web site. After the web site was moved to a different server, the clean-up process for that folder failed due to a lack of access rights. But that was long ago. I looked into that folder, and it was empty. But wait, that line mentioned in the error message does something different! Before the temporary image file is created, I ask Windows to give me a file name. I created such a superb function for that purpose:

                      Public Function getTempFileName(Optional ByVal Extension As String = "tmp") As String
                      Dim strFileName As String

                      'system temp file name
                      strFileName = System.IO.Path.GetTempFileName
                      
                      'file name only
                      strFileName = strFileName.Substring(System.IO.Path.GetTempPath.Length)
                      
                      'default extension is "tmp", if we want a different one, we must exchange it
                      If Extension <> "tmp" Then
                          strFileName = strFileName.Substring(0, strFileName.Length - 3) & Extension
                      End If
                      
                      'done
                      Return strFileName
                      

                      End Function

                      Overwhelmed by the beauty of this piece of code (it will surely be honored as the proper solution to that problem in many VB and aspx fora throughout the web soon), you'll likely not see how this function can fail. Also I had to take a look into Microsoft's documentation: Not only does System.IO.Path.GetTempFileName return the full path for a temporary file, it does al

                      Richard DeemingR Offline
                      Richard DeemingR Offline
                      Richard Deeming
                      wrote on last edited by
                      #10

                      If you just want to generate a random filename without creating a file, try Path.GetRandomFileName[^] instead.


                      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                      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