Export To Word...non-edittable

Is there a way that I can make an exported word document non-edittable.

What I have now is a way to export a timecard usgin the following code:
weekNum = 44
Response.Buffer = True
Response.ContentType = "application/vnd.ms-word"
Response.AddHeader "content-disposition", "attachment; filename = "&un&"_"&replace(weekNum,"/","")&"_timecard.doc"

however I can edit the document,what I need to do is make this non-edittable....
LVL 25
Who is Participating?

Improve company productivity with a Business Account.Sign Up

hc0904pcdConnect With a Mentor Commented:
sample code,

Dim sRTF
Dim fso, MyFile, sFileName
Dim Conn, rs

Response.Buffer = True

'then open the db

'create the file for the RTF
Set fso    = CreateObject("Scripting.FileSystemObject")
sFileName  = "tempfile.doc"
Set MyFile = fso.CreateTextFile(Server.MapPath(".") & "\" & sFileName, True)

'Write the font table
sRTF = "{\fonttbl {\f0\froman\fcharset0 Times New Roman;}" & _
                  "{\f1\fswiss\fcharset0 Arial;}" & _
                  "{\f2\fmodern\fcharset0 Courier New;}}"
MyFile.WriteLine sRTF

'write the protection bits
MyFile.WriteLine("{\formprot }" & "\par")
MyFile.WriteLine("{\allprot }" & "\par")
'      MyFile.WriteLine("{\formshade }" & "\par")      

'write the title and author for the document properties      
MyFile.WriteLine("{\info{\title test doc}" & _
                                                "{\author test}}")

'Write the document header and footer
MyFile.WriteLine("{\header\pard\qc\brdrb\brdrs\brdrw10\brsp100" & _
                                                "{\fs50 Test File } \par}")
MyFile.WriteLine("{\footer\pard\qc\brdrt\brdrs\brdrw10\brsp100" & _
                                                "{\fs18 test footer info\par " & _
                                                " } \par}")

do while not rs.eof
      MyFile.WriteLine   "\fs26\f1"   'Default font
      MyFile.WriteLine   "\pard"                  'don't know what this is
      MyFile.WriteLine   "\par"                        'para
      MyFile.WriteLine   rs.Fields("un").Value & "    "
      MyFile.WriteLine   rs.Fields("weekNum").Value & "    "
'      MyFile.WriteLine   "\par}"
'      If Not(rs.eof) Then MyFile.WriteLine("\pard \page")      'write a pagebreak
      MyFile.WriteLine("\pard ")      
end if

Set rs = Nothing
Set Conn = Nothing

'write the form fields - not sure if this is still required
MyFile.WriteLine("\formfield ")            'open form field
MyFile.WriteLine("\fftype0 ")                  'form field type - 0 is text
MyFile.WriteLine("\ffprot1 ")                  'protect form
'      MyFile.WriteLine("\ ")            
'close the RTF string and file

Response.Write _
      "<META HTTP-EQUIV=""REFRESH"" Content=""0;URL=" & sFileName & """>"

Hi kevp,
By non-editable do you mean write protected?
If so, could you, instead of creating a word file on the fly, first create a word file in word and make it write protected (and possibly also password protected to prevent editing?) and load that to your server... and then instead of creating a new word file each time, you use fso to make a copy of the file, and then edit it.
Would that work in your situation?

I just figured the obvious - if the file is created as read only then you can't edit it as you need to...
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

kevp75Author Commented:
well....good idea, but not along the lines that I need to do.

I made a time clock app, people clock in/out and then can view there timecards.

I then allow them to print it or export it to word (via the code above), so nothing gets saved on the server (well...except for the data in the db), however I noticed that when I export it, the document is edittable.

They wouldn't be able to change their time in the db (only admin can do this), however they can change it in the doc they exported, which I would like to do away with.  I had it exporting to PDF (which I could set to protect so they could not edit it...using ABCPDF), however, I would like to be able to do something similar with the word export.....
I don't think you can write protect a word doc, thats hwy pdf is so popular

would password protecting the word file help?
you can protect a file so that anyone can open it but nobody can edit it.
You can password protect it but they can stil edit it.

Sorry dude!

Whats the problem with using PDF?


kevp75Author Commented:
there isn't a problem using PDF, and I currently do, however the question is not about using one or the other (as I want to do both)....

it's about making the word document un-edittable on export.  The file is not saved anywhere it's streamed directly to the browser upon export (as per the code in the question)

@hc, how would I password protect a file that is being streamed to the browser?

@Loren, if it is password protected, how can it still be edittable?
kevp75Author Commented:
i guess it really does not ultimately matter if either PDF export, or Word export are edittable, as the admin has control over what is in the db (which is what is getting exported)

However, since I can currently password protect the PDF (preventing it from being edittable), it would be nice to be able to do the same with the Word export...
hi kev,
Initially I thought that to create a password protected file you would need to start from having a word file on your server which you could use as a template. But then I dounf this rather interesting article ... www.expresscomputeronline.com/20030120/techspace1.shtml  - could you have a read of this and let me know if it's heading in the right direction? It's a slightly long-winded artcile, but I think worth the read.
kevp75Author Commented:
it is in the right direction, however....  (and this is a big however)


it is only streamed to the client via the code above.

Now, if it is possible to save the file to the server (with the edit protection in place), then stream the file, then delete it (as it is not needed to store the file on the server) than great, however, I know as well as just about anybody, that saving the file is no problem, deleting the file is no problem.  Making it un-editable is, and streaming it afterwards is....hence we come back around to my original question...
hi kev,
how urgent is your need for a solution?
i'd like to do some testing, but i'm up against a work deadline and can't do much in the next 8-10 hours
kevp75Author Commented:
not urgent at all.  I originally had plans to get this site fully launched by EOY, but I am already going to end up being well beyond that  :)

I'll post here if I come p with anything in the meantime
okay great
i'll have a go overnight... and in the meantime someone else might popin with a solution...
hi kevp,
I've got it working, creating a protected RTF file on the server and then streaming it. Will that format work for you?

kevp75Author Commented:
that would work.
my testing results in a word file which i cannot edit.
main sources/credits for this are

If this works in principle you may be able to adapt it so it doesn't need to use rtf.
Maybe xml?
ahhh. the perils of fast testing, on closer inspection it's only a partial solution.

It would stop most people who casually try to edit the file, but if you open the forms toolbar and deselect the "protect form" button, then you can edit the file.

Back to the drawing board.
kevp75Author Commented:
i appreciate it.  I will check it out later on tonight (hopefully....)
I think the way forward is to get the password for forms protection in to the file. Possibly that won't take in that format so I'll look at whether the technique will work in creating a word doc file, and if that won't work I'll try xml.
hc0904pcdConnect With a Mentor Commented:
hi kev,
A different tack - I created a word file in word 2003, with a formfield inserted as in Dr. Nitin Paranjape's sample. Then I saved it as an xml file and inspected the code. There is a line that goes something like this,  
<w:documentProtection w:edit="read-only" w:enforcement="on" w:unprotectPassword="1FXXXetc"/>

I'm thinking that it doesn't matter what the password is, there simply needs to be one, and that will prevent users from disabling the forms protection which in turned blocks the file from being edited.

Can you try to either, create your word file using asp & xml and adding the above line, or find a way to add the equivalent of the above line in your existing code?
thanks for points, hope it was useful?
kevp75Author Commented:
Actually, I knicked the idea, realizing that the actual data is stored in the db anyways, so...I really don't have to worry whether it's secured or not.

However, I did try that out on another instance (where it didn't matter, yet again....i just love wasting my time...LOL), and it did the trick :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.