How to save an excel file with Read-only

I would like to save an excel file with read-only option.
Are there any better ways to do that other than keep clicking buttons?

Thank you!

You could try this…

  1. Add an Invoke Code activity
  2. Add an argument to the Invoke Code activity called ‘filepath’
  3. Add the below script to the code parameter
  4. Pass the filepath of your saved Excel file to the filepath argument.

System.IO.File.SetAttributes(filePath, System.IO.File.GetAttributes(filePath) Or FileAttributes.ReadOnly)


1 Like


Hope this thread would help you resolve this

Cheers @yesterday

1 Like

It worked! Thank you so much!!!

1 Like

Thank you so much! It was very helpful!!

I want to remove the read-only attribute, and I replaced “readonly” with “Normal”, but it did not remove read-only attribute.

System.IO.File.SetAttributes(filePath, System.IO.File.GetAttributes(filePath) Or FileAttributes.Normal)

I get an error when updating the file.
The error is access to the path is denied.

How do I remove read-only??

What I want to do is:

Everyday a robot updates an excel file and make a copy of it.
I want to make the copied file to be read-only so that the file will not be updated accidentally.
But the filename is always same, and updated, I need to remove read-only first and then overwrite, and make the file read-only again.

I use to Copy File activity (Overwrite checked).

To remove read only, change the script to this:

System.IO.File.SetAttributes(filePath, System.IO.File.GetAttributes(filePath) Xor FileAttributes.ReadOnly)

Essentially ‘Or’ will add the read only attribute and ‘Xor’ will remove it.

1 Like

I am getting error

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.