2
votes

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.

1

1 Answers

0
votes

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