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. FileAttribute

FileAttribute

Scheduled Pinned Locked Moved C#
question
3 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.
  • M Offline
    M Offline
    Mazdak
    wrote on last edited by
    #1

    I have a file and waana check if it has ReadOnly attribute,if its true change it to write in it. I use this code:

    if(File.GetAttributes(filename) == FileAttributes.ReadOnly)
    File.SetAttributes( filename , FileAttributes.Normal );

    FileStream myfile = File.Open( filename ,System.IO.FileMode.Open , System.IO.FileAccess.ReadWrite );

    //write something in the file

    But when it reached to readonly file it does not change the ReadOnly attribute. Mazy "The path you tread is narrow and the drop is shear and very high, The ravens all are watching from a vantage point near by, Apprehension creeping like a choo-train uo your spine, Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd

    J 1 Reply Last reply
    0
    • M Mazdak

      I have a file and waana check if it has ReadOnly attribute,if its true change it to write in it. I use this code:

      if(File.GetAttributes(filename) == FileAttributes.ReadOnly)
      File.SetAttributes( filename , FileAttributes.Normal );

      FileStream myfile = File.Open( filename ,System.IO.FileMode.Open , System.IO.FileAccess.ReadWrite );

      //write something in the file

      But when it reached to readonly file it does not change the ReadOnly attribute. Mazy "The path you tread is narrow and the drop is shear and very high, The ravens all are watching from a vantage point near by, Apprehension creeping like a choo-train uo your spine, Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      Try this instead if( (File.GetAttributes(filename) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly ) James Simplicity Rules!

      M 1 Reply Last reply
      0
      • J James T Johnson

        Try this instead if( (File.GetAttributes(filename) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly ) James Simplicity Rules!

        M Offline
        M Offline
        Mazdak
        wrote on last edited by
        #3

        Thank you,I'll check it as soos as I go home. :) Mazy "The path you tread is narrow and the drop is shear and very high, The ravens all are watching from a vantage point near by, Apprehension creeping like a choo-train uo your spine, Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd

        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