Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

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
un="me"
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....
0
kevp75
Asked:
kevp75
  • 13
  • 8
  • 3
2 Solutions
 
hc0904pcdCommented:
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?
 

0
 
hc0904pcdCommented:
I just figured the obvious - if the file is created as read only then you can't edit it as you need to...
0
 
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.....
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LTY83Commented:
I don't think you can write protect a word doc, thats hwy pdf is so popular

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

Sorry dude!

Loren
0
 
LTY83Commented:
Whats the problem with using PDF?

Thanks,

Loren
0
 
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?
0
 
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...
0
 
hc0904pcdCommented:
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.
0
 
kevp75Author Commented:
it is in the right direction, however....  (and this is a big however)

THE FILE DOES NOT GET SAVED TO THE SERVER....

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...
0
 
hc0904pcdCommented:
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
0
 
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
0
 
hc0904pcdCommented:
okay great
i'll have a go overnight... and in the meantime someone else might popin with a solution...
0
 
hc0904pcdCommented:
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?



0
 
kevp75Author Commented:
that would work.
0
 
hc0904pcdCommented:
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)

MyFile.WriteLine("{\rtf1")
'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 ")      
      rs.MoveNext
loop
end if

rs.Close
Conn.Close
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
MyFile.WriteLine("}")
MyFile.Close

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

0
 
hc0904pcdCommented:
my testing results in a word file which i cannot edit.
main sources/credits for this are
http://www.expresscomputeronline.com/20030120/techspace1.shtml
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnrtfspec/html/rtfspec_16.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnrtfspec/html/RTFSpec_62.asp

If this works in principle you may be able to adapt it so it doesn't need to use rtf.
Maybe xml?
0
 
hc0904pcdCommented:
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.
0
 
kevp75Author Commented:
i appreciate it.  I will check it out later on tonight (hopefully....)
0
 
hc0904pcdCommented:
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.
0
 
hc0904pcdCommented:
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?
0
 
hc0904pcdCommented:
thanks for points, hope it was useful?
0
 
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 :)
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 13
  • 8
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now