如何使网页检查链接文件是否具有错误的文件类型以检查其他文件类型?

发布于 2024-11-25 12:58:27 字数 297 浏览 1 评论 0原文

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

I am making a webpage that is going to have a large amount of Word documents linked on it for review. I am formatting Word lists of the files to be reviewed into a HTML page and use a macro to generate the links for the files to be reviewed. The macro generates the links to be linked to .doc files. My company recently starting moving to Word 2010, but some users are still using Word 2003, so we have files being submitted in .doc format and some being submitted in .docx format. I am looking for a way in ASP, ASP.NET, or JavaScript to have the the webpage to see if file is not on the server in a .doc file format to check to see if there exists a file with the that sane file name that is in a .docx file format. Any suggestions would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千寻… 2024-12-02 12:58:27

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

假设您使用 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

You obviously should do checking on the server side.

Assuming that you use VB.net and all files are being kept in the same directory the following code might help you:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文