How to set a excel file readonly?

Thank you

Answer this question

How to set a excel file readonly?

  • Joselillo

    To set the information/attributes, we use the File.SetAttributes in the System.IO namespace:

    System.IO.File.SetAttributes("File.xls", FileAttributes.ReadOnly);

    and thats it!

    to set multiple attributes, simply add another FileAttribute (OR)

    System.IO.File.SetAttributes("File.xls", FileAttributes.ReadOnly | FileAttributes.Hidden);

    would make it readonly and hidden.

     

    To undo this, or rather set the attributes back, then you need to use FileAttributes.Normal, on its own:

    System.IO.File.SetAttributes("File.xls", FileAttributes.Normal);

     

    does this help



  • jeffery chan

    Yes, I want to know how to set the file readonly programmatically.
  • DMottorn

    you need to explain much more than that I'm afraid. Are you talking about the file itself to set the readonly attribute programmatically

  • How to set a excel file readonly?