How to detect if a Word document is password protected before uploading the file to server?

后端 未结 5 545
余生分开走
余生分开走 2020-12-12 05:57

I am working on a website, which allows users to upload different file formats. We need to restrict the user from uploading password protected files.

Is there a way

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 06:43

    Like notme I am unaware of a way to tell if a file is password protected prior to getting even part of a file uploaded, but the accepted answer to this question, while technically great, is a bit of overkill.

    See Detect password protected word file for a much simpler and faster method to test whether a file is password protected.

    Also, for those finding this question looking for the solution in VBA/S, the following is the version in the former, which is easily adaptable to the latter. www.ozgrid.com/forum/showthread.php?t=148962 . Though I would suggest checking for err.number = 5408 (what gets thrown with a wrong password, when protected), rather than using any err.number to determine that file is password protected.

提交回复
热议问题