tags:

views:

122

answers:

1

Hello friends,,I am creating a file in which I will have some details in it...I dont any body to edit it..so I decided to keep that as read only file...I tried the following code but its popping an exception when I am setting the status...Please tel me if there are any alternative

CFile test(L"C:\\Desktop\\myText.txt",CFile::modeCreate|CFile::modeWrite);
CFileStatus status;
test.GetStatus(status);
status.m_attribute = CFile::readonly;
test.SetStatus(L"C:\\Desktop\\myText.txt",status);
+1  A: 

Try one of the following:

  1. Close the file before changing the status with a call to CFile::Close() (test.Close() in your example.)
  2. OR in the readonly attribute with the existing attributes, e.g. status.m_attribute |= CFile::readonly.
Rob
I tried the first point and its working ...thank u very much
kiddo