saveDoc.aspx
上传用户:tiancihang
上传日期:2014-03-12
资源大小:21387k
文件大小:3k
- <%@ Page Language="VB" AspCompat ="true" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <script language =vbscript runat="server">
- '为了增强安全性,开发者可增加验证当前用户的功能,例如通过Session等
- '防止用户自己写客户端脚本向savedoc.aspx提交非法文件
- Dim strReturnString, sFileName, sRelativePath
- Function SaveFile(ByVal sFilePath, ByVal sContent)
- On Error Resume Next
- Dim oStream
- oStream = Server.CreateObject("ADODB.Stream")
-
- oStream.Type = 1
- oStream.Open()
- oStream.Write(sContent)
- oStream.SaveToFile(sFilePath, 2)
-
- oStream.close()
- oStream = Nothing
- SaveFile = True
- If Err.Number <> 0 Then
- SaveFile = False
- End If
- End Function
-
- Sub ReadAndSaveFile()
- On Error Resume Next
- Dim i
- Dim sFileContent
- Dim oXML
- oXML = Server.CreateObject("Msxml2.DOMDocument")
- oXML.async = False
- oXML.load(Request)
-
- 'sFileContent 是 word二进制流,此流可以保存成文件,也可以保存到数据库。
-
- sFileContent = oXML.documentElement.childNodes.item(0).nodeTypeValue
- 'FileName和RelativePath区分大小写
- sFileName = oXML.documentElement.childNodes.item(0).Attributes.getNamedItem("FileName").Text
- sRelativePath = oXML.documentElement.childNodes.item(0).Attributes.getNamedItem("RelativePath").Text
-
- '得到文件扩展名
- Dim intP, strFileExName
- intP = InStrRev(sFileName, ".")
- strFileExName = Mid(sFileName, intP)
-
- If strFileExName = ".doc" Or strFileExName = ".xls" Or strFileExName = ".ppt" Or strFileExName = ".wps" Then
- SaveFile(Server.MapPath(".") & "" & sRelativePath & sFileName, sFileContent)
- End If
-
- oXML = Nothing
- If Err.Number <> 0 Then
- strReturnString = "-1"
- End If
- End Sub
-
- Sub UpdateTime()
- Dim conn, dbpath
- conn = Server.CreateObject("ADOCO.Connection")
- dbpath = Server.MapPath("demodata/soademo.mdb")
- conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath)
- Dim strsql
-
- '********************************************************************
- ' 读数据库相关操作
- strsql = "update word set submitTime='" & Now() & "' where fileName='" & sFileName & "'"
- conn.execute(strsql)
- conn.Close()
- ' 释放数据库连接对象
- conn = Nothing
- End Sub
-
-
- Sub Page_Load()
- '执行文件
- ReadAndSaveFile()
- If strReturnString = "-1" Then
- Response.Write("保存错误!")
- Else
- UpdateTime() ' 如果您需要更新文件列表中"修改时间" ,就执行此过程.
- Response.Write("保存成功!")
- End If
- End Sub
- </script>
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head runat="server">
- <title>无标题页</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
-
- </div>
- </form>
- </body>
- </html>