Click here to Skip to main content
15,885,953 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Does anyone know how to change the read-only attribute for a file using VB.NET?

I have a file that is read-only and I want to be able to write to it.
Posted
Updated 6-Jul-10 5:44am
v2
Comments
Sandeep Mewara 6-Jul-10 1:20am    
What do you mean by unlock?
Is it read-only and you want it to be writable?

This may helps you...Check it out

regards
 
Share this answer
 
Comments
Nish Nishant 13-Jul-10 13:43pm    
Reason for my vote of 5
Good link. Pity CP does not have an article we could link to. Worth a 5!
The standard answer for this type of question is, google it!

A simple google search returned this article as the first hit:

Set file attributes: Hidden, ReadOnly[^]

Granted, you would have to know how to change the word true to false, but you should be able to figure that out.

And next time, try to make your title fit your question. The title looked like you wanted to "lock" a file, not change it from read-only.
 
Share this answer
 
Dear koolprasad20032

Thank you ur help but i have been though the link that u gave me. After i done all the step, i got an error and i cant solve it.

the error said ....

File, FileAttributes are not declared.. So what type of data i need to declare for File and FileAttributes?


Is that a String??



Thank you for your help again..
 
Share this answer
 
Sub ChangeAtt(ByVal filePath As String)
       System.IO.File.SetAttributes(filePath, System.IO.File.GetAttributes(filePath) Xor FileAttributes.ReadOnly Or FileAttributes.Hidden)
   End Sub


xor:to remove attribute from file attributes
or: to add attribute to file attributes
 
Share this answer
 
Comments
HanuBaba 8-Jul-10 1:47am    
Reason for my vote of 1
uilg

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900