I have an app where the user can add an attachment using FileDialog, Directory, and Copy. But, I need to make the document they are saving (regardless of extension) a read-only document when it is saved to a new location. Is this possible?
I’m only a year into using Clarion 9 - so please be kind/programmer friendly with the examples/explanations.
I know this works. You want to Get, modify then Set to preserve other existing attributes. Just reverse the Strip logic to Add with BOR(Attrs,FILE_ATTRIBUTE_READONLY)
SetFileAttributes(*CSTRING,LONG),BOOL,PASCAL,DLL(1),RAW,NAME('SetFileAttributesA'),PROC
GetFileAttributes(*CSTRING),LONG,PASCAL,DLL(1),RAW,NAME('GetFileAttributesA')
FileStripReadOnly FUNCTION (string _filename)!,BOOL ! Declare Procedure
Attrs LONG,AUTO
CFN CSTRING(261),AUTO
RetBool BOOL,AUTO
FILE_ATTRIBUTE_READONLY EQUATE( 00000001h)
INVALID_FILE_ATTRIBUTES EQUATE(0FFFFFFFFh) !(DWORD (-1))
CODE
RetBool = 0
CFN = CLIP(_filename)
Attrs = GetFileAttributes(CFN) !If the function fails, the return value is INVALID_FILE_ATTRIBUTES.
IF Attrs <> INVALID_FILE_ATTRIBUTES
IF BAND(Attrs, FILE_ATTRIBUTE_READONLY)
Attrs -= FILE_ATTRIBUTE_READONLY
IF SetFileAttributes(CFN,Attrs) !If the function succeeds, the return value is nonzero.
RetBool = True
END
END
END
RETURN RetBool
What they said. You need to save the file as usual and then use some method to change the file attribute to read only.
There are many 3rd part utils for this in addition to that above