gpt4 book ai didi

javascript - 如何进行网页检查以查看链接文件是否具有错误的文件类型以检查另一种文件类型?

转载 作者:行者123 更新时间:2023-11-30 06:46:03 26 4
gpt4 key购买 nike

我正在制作一个网页,该网页将链接大量 Word 文档以供审阅。我正在将要审阅的文件的 Word 列表格式化为 HTML 页面,并使用宏生成要审阅的文件的链接。该宏生成要链接到 .doc 文件的链接。我公司最近开始迁移到 Word 2010,但一些用户仍在使用 Word 2003,因此我们提交的文件以 .doc 格式提交,一些文件以 .docx 格式提交。我正在 ASP、ASP.NET 或 JavaScript 中寻找一种方法来让网页查看文件是否以 .doc 文件格式存在于服务器上,以检查是否存在具有该合理文件名的文件这是一个.docx 文件格式。任何建议将不胜感激。

最佳答案

您显然应该在服务器端进行检查。

假设您使用 VB.net 并且所有文件都保存在同一目录中,以下代码可能对您有所帮助:

Dim strRequest As String = Request.QueryString("file")
If strRequest <> "" Then
Dim path As String = Server.MapPath(strRequest)
Dim docxPath As String = System.IO.Path.ChangeExtension(path, ".docx")
Dim file As System.IO.FileInfo = New System.IO.FileInfo(docxPath)
If file.Exists Then 'set appropriate headers
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" & file.Name)
Response.AddHeader("Content-Length", file.Length.ToString())
Response.ContentType = "application/octet-stream"
Response.WriteFile(file.FullName)
Response.End
Else
' Do the same but for the original path

关于javascript - 如何进行网页检查以查看链接文件是否具有错误的文件类型以检查另一种文件类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6784310/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com