Solved

Export To Word...non-edittable

Posted on 2006-11-11
24
302 Views
Last Modified: 2008-02-01
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
Comment
Question by:kevp75
  • 13
  • 8
  • 3
24 Comments
 
LVL 6

Expert Comment

by:hc0904pcd
ID: 17924389
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
 
LVL 6

Expert Comment

by:hc0904pcd
ID: 17924431
I just figured the obvious - if the file is created as read only then you can't edit it as you need to...
0
 
LVL 25

Author Comment

by:kevp75
ID: 17925206
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
 
LVL 4

Expert Comment

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

sorry
0
 
LVL 6

Expert Comment

by:hc0904pcd
ID: 17926658
would password protecting the word file help?
you can protect a file so that anyone can open it but nobody can edit it.
0
 
LVL 4

Expert Comment

by:LTY83
ID: 17926743
You can password protect it but they can stil edit it.

Sorry dude!

Loren
0
 
LVL 4

Expert Comment

by:LTY83
ID: 17926746
Whats the problem with using PDF?

Thanks,

Loren
0
 
LVL 25

Author Comment

by:kevp75
ID: 17926861
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
 
LVL 25

Author Comment

by:kevp75
ID: 17926875
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
 
LVL 6

Expert Comment

by:hc0904pcd
ID: 17926900
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
 
LVL 25

Author Comment

by:kevp75
ID: 17927175
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
 
LVL 6

Expert Comment

by:hc0904pcd
ID: 17927213
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 25

Author Comment

by:kevp75
ID: 17927272
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
 
LVL 6

Expert Comment

by:hc0904pcd
ID: 17927298
okay great
i'll have a go overnight... and in the meantime someone else might popin with a solution...
0
 
LVL 6

Expert Comment

by:hc0904pcd
ID: 17934878
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
 
LVL 25

Author Comment

by:kevp75
ID: 17934924
that would work.
0
 
LVL 6

Accepted Solution

by:
hc0904pcd earned 500 total points
ID: 17934925
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
 
LVL 6

Expert Comment

by:hc0904pcd
ID: 17934939
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
 
LVL 6

Expert Comment

by:hc0904pcd
ID: 17934954
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
 
LVL 25

Author Comment

by:kevp75
ID: 17935001
i appreciate it.  I will check it out later on tonight (hopefully....)
0
 
LVL 6

Expert Comment

by:hc0904pcd
ID: 17935009
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
 
LVL 6

Assisted Solution

by:hc0904pcd
hc0904pcd earned 500 total points
ID: 17935245
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
 
LVL 6

Expert Comment

by:hc0904pcd
ID: 18024345
thanks for points, hope it was useful?
0
 
LVL 25

Author Comment

by:kevp75
ID: 18024391
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now