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. General Programming
  3. C#
  4. Last modified time in file.

Last modified time in file.

Scheduled Pinned Locked Moved C#
xmltutorial
5 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.
  • K Offline
    K Offline
    Karmendra Suthar
    wrote on last edited by
    #1

    Hi, I don't know from which heaven I got this idea of storing last modified time in side the XML file, as a node. But I will tell you why I need this, and can you tell me how am I suppose to do it. I want to prevent user to hack my file, they shouldn't be able to modify it and save it. If they do that, I delete that file and recreate a newer one. (Like giving monkey a banana locked inside a transparent box, he can see it but can't eat it :) ) But to accomplish this I need to store the last modified time in the file and on save do not modify the last modified time. If I am sounding crazy, let me know I will explain with an detailed example. Thanks for you Precious time, Karmendra

    K 1 Reply Last reply
    0
    • K Karmendra Suthar

      Hi, I don't know from which heaven I got this idea of storing last modified time in side the XML file, as a node. But I will tell you why I need this, and can you tell me how am I suppose to do it. I want to prevent user to hack my file, they shouldn't be able to modify it and save it. If they do that, I delete that file and recreate a newer one. (Like giving monkey a banana locked inside a transparent box, he can see it but can't eat it :) ) But to accomplish this I need to store the last modified time in the file and on save do not modify the last modified time. If I am sounding crazy, let me know I will explain with an detailed example. Thanks for you Precious time, Karmendra

      K Offline
      K Offline
      Karmendra Suthar
      wrote on last edited by
      #2

      I got it, this,

      File.SetLastWriteTime(FileName,LastWriteTime);

      would do the job. Thanks.

      P 1 Reply Last reply
      0
      • K Karmendra Suthar

        I got it, this,

        File.SetLastWriteTime(FileName,LastWriteTime);

        would do the job. Thanks.

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

        That might only stop casual users, and it could cause the file to be deleted even if no changes were made. I can write something that does the same thing and bypasses your "security". You would likely have to store the date somwewhere inaccessable. Or encrypt the date and a hash of the file or something. I wouldn't bother trying to "secure" the file this way. Even Visual Studio doesn't. When I modify a file (even project files) with Notepad it merely asks if I want to reload the file and accept the "unauthorized" changes.

        K 1 Reply Last reply
        0
        • P PIEBALDconsult

          That might only stop casual users, and it could cause the file to be deleted even if no changes were made. I can write something that does the same thing and bypasses your "security". You would likely have to store the date somwewhere inaccessable. Or encrypt the date and a hash of the file or something. I wouldn't bother trying to "secure" the file this way. Even Visual Studio doesn't. When I modify a file (even project files) with Notepad it merely asks if I want to reload the file and accept the "unauthorized" changes.

          K Offline
          K Offline
          Karmendra Suthar
          wrote on last edited by
          #4

          I am doing this not for cs files but my own configuration file, and it is not if user see the data but if he modifies it it will be replaced with default. i am storing a checkbox value true or false. Actually I am no good with encryption, I wasn't able to choose one to use. I actually don't want the user to modify the config file outside of my application. Can you tell me other ways to prevent it? Thanks for your words. Karmu

          P 1 Reply Last reply
          0
          • K Karmendra Suthar

            I am doing this not for cs files but my own configuration file, and it is not if user see the data but if he modifies it it will be replaced with default. i am storing a checkbox value true or false. Actually I am no good with encryption, I wasn't able to choose one to use. I actually don't want the user to modify the config file outside of my application. Can you tell me other ways to prevent it? Thanks for your words. Karmu

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

            KSuthar wrote:

            Can you tell me other ways to prevent it?

            No, I can't think of a way to be sure. And I don't think it's a reasonable goal. If the user wants to modify the file outside the application, why not allow it? It seems to me that the application needs to: 0) Check that the file exists 1) Load it into an XmlDocument 2) Check the schema 3) Read the value and confirm that's it either True or False 4) If anything in that process fails, then use the default, otherwise you got a valid value, why do you care how it got there? You might also consider a binary file rather than an XML (text) file, to make modification more difficult.

            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