【问题标题】:How can I make a webpage check to see if a link file has the wrong file type to check for another file type?如何使网页检查以查看链接文件是否具有错误的文件类型以检查另一种文件类型?
【发布时间】:2011-07-22 00:06:09
【问题描述】:

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

【问题讨论】:

    标签: javascript asp.net docx doc


    【解决方案1】:

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

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

    【讨论】:

    • 我当然是在服务器端进行检查。我想我应该改写那部分。不幸的是,我使用 C#(我还在学习),但我得看看办公室里的其他人是否会做一些 VB.net 编程。但感谢您的回应。
    猜你喜欢
    • 2017-05-09
    • 2012-10-02
    • 1970-01-01
    • 1970-01-01
    • 2016-08-28
    • 1970-01-01
    • 2023-03-21
    • 2011-08-02
    • 2013-08-26
    相关资源
    最近更新 更多