Home Forums General XMetaL Discussion How to open a file "Read Only" in XMetal Author 5.5 in Jscript? Reply To: How to open a file "Read Only" in XMetal Author 5.5 in Jscript?

Derek Read

Reply to: How to open a file "Read Only" in XMetal Author 5.5 in Jscript?

Our Open() API does not support a parameter that lets you set a file's read-only attribute. If you pass a number as the second parameter that is interpreted as the view to open the document in. See your copy of the Programmers Guide (or [url=http://na.justsystems.com/webhelp/en/xmetaldeveloper/pg/6.0/pg.html#Open]Documents.Open[/url])

JScript doesn't have such functionality either. I suspect you might be reading Microsoft's documentation for the File System Object (aka: FSO), so you are close but not quite at the right location.

To do what you want to do (a bit of guessing here) you would call our Documents.Open() API as documented in the Programmers Guide and then you might make an additional call to FSO. FSO is not the only way to do this, but it is easy to use with JScript. Following is adapted from http://msdn.microsoft.com/en-us/library/5tx15443%28VS.85%29.aspx

//XMetaL Script Language JScript:
function setReadOnlyBit(filespec,boolSet) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.GetFile(filespec);
if (f.attributes & 1) {
if(boolSet == false) {
f.attributes = f.attributes - 1;
else {
if(boolSet == true) {
f.attributes = f.attributes + 1;

var filepath = "C:\temp\mytestfile.xml";

//pass true to add the read-only bit
Application.Alert("read only bit has been set (check before dismissing this dialog)");

//pass false to remove the read-only bit
Application.Alert("read only bit has been removed");

Keep in mind that XMetaL Author will allow you to open files with this bit set. It is up to the customizer to decide what the product's behavior should be in this case. With most of the CMS integrations for XMetaL a “read only” file (which may have different meanings in the CMS sense) is allowed to open but the CSS that styles the file is changed to show the entire document with a grey background (or similar indicator) and a call to an API named Selection.ReadOnly is run on the root element so the author does not waste time editing the file (in most CMS systems there is no concept of “Save As”). In your case, if you are storing files on the local file system you might wish to allow users to both open and edit these files. In this case XMetaL Author should ask the author to do a Save As when they try to Save (unless you have overridden those commands by creating your own Save and / or Save As functionality).

If your goal is to allow multiple users to work on the same files without overwriting changes other people have made you may wish to look at one of the existing integrations we have with various CMS systems. If your budget is low you might also look at SVN or Mercurial.