6 Replies Latest reply: Aug 27, 2007 1:41 PM by Newsgroup_User RSS

    How can I display the date a word document was last modified on my web page?

    b718
      I have lists of links to word documents on my web pages. I want to be able to show the date the word document was last modified next to each link. My pages are straight html. Thanks.
        • 1. Re: How can I display the date a word document was last modified on my web page?
          bregent MVP
          What server side scripting language are you using?
          • 2. Re: How can I display the date a word document was last modified on my web page?
            b718 Community Member
            Good question. I'm not sure but we do use ASP. I don't really know much about coding but if you have a suggestions I'm more than willing to try it out. I had a feeling this would require some back end coding but again - I am willing to give it a try.
            • 3. Re: How can I display the date a word document was last modified on my web page?
              Günter Schenk Community Member
              I have no clue of ASP, but I found some info related to "ASP file object" on w3schools.com -- more precisely, on this page, which also provides a "file last modified" example

              hope this helps
              • 4. Re: How can I display the date a word document was last modified on my web page?
                b718 Community Member
                Ok - this worked:
                <%
                dim fs, f
                set fs=Server.CreateObject("Scripting.FileSystemObject")
                set f=fs.GetFile(Server.MapPath("copy/salesCompPlanCanadianSalespeople.doc"))
                Response.Write("Last modified on: " & f.DateLastModified)
                set f=nothing
                set fs=nothing
                %>

                but I would have to go to each individual file (I have hundreds) and put this code on each link.
                • 5. Re: How can I display the date a word document was last modified on my web page?
                  bregent MVP
                  >but I would have to go to each individual file (I have hundreds) and put this code on each link.

                  No, you can use the FileSystemObject to get a list of the files in the directory. See if you can adapt this for your site:

                  <link href="/CSS/dirlist.css" rel="stylesheet" type="text/css">
                  <%
                  Function FormatSize(SizeInBytes)

                  if SizeInBytes > 1024^2 then
                  FormatSize = formatnumber(SizeInBytes / 1024^2,2) & " MB"

                  elseif SizeInBytes > 1024 then
                  FormatSize = formatnumber(SizeInBytes / 1024,2) & " KB"

                  else
                  FormatSize = SizeInBytes & " Bytes"
                  end if

                  end function
                  %>
                  <%
                  dim parts
                  dim part
                  dim BrowseLine
                  dim RelLink
                  dim i

                  url = Request.ServerVariables("URL")

                  Parts = split(URL,"/")

                  for part = 1 to ubound(Parts)-1

                  ' calc link
                  RelLink = ""
                  for i = 1 to ubound(Parts) - part - 1
                  RelLink = RelLink & "..\"
                  next

                  If trim(BrowseLine) <> "" then
                  BrowseLine = BrowseLine & "/"
                  end if

                  BrowseLine = BrowseLine & "<A href=" & RelLink & ">" & parts(part) & "</A>"


                  next

                  ' add "back" link
                  BrowseLine = Browseline & "  " & "<A href='javascript:history.back();'><img src='/images/return.gif' border=0></A>"

                  Response.Write "<P class = 'NavTop'>" & BrowseLine & "</P>"


                  ' -----------------------------\

                  Dim fso
                  set fso = server.CreateObject("Scripting.fileSystemObject")
                  dim fldr
                  dim fle


                  %>
                  <a href="../index.asp"><img src="../images/leftbanner.jpg" width="343" height="70" border="0"></a>
                  <link href="/CSS/dirlist.css" rel="stylesheet" type="text/css">
                  </p>
                  <p></p>
                  <table width="85%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                  <th width="63%"><div align="left">   Document Name</div></th>
                  <th width="14%">Size</th>
                  <th width="23%"><div align="left">  Date</div></th>
                  </tr>

                  <%
                  ' display folders
                  for each fldr in fso.GetFolder(server.MapPath(".")).SubFolders

                  %>
                  <tr>
                  <td class="FileName"> <a href='<%= fldr.Name %>'><img src="/images/folder.gif" border=0> <%= fldr.Name %></a></td>
                  <td class="FileSize">  <%= FormatSize(fldr.Size) %></td>
                  <td class="FileDate"><div align="left">  <%= FormatDateTime(fldr.DateLastModified,2) %></div></td>
                  </tr>
                  <%
                  next
                  %>


                  <%
                  ' display files
                  for each fle in fso.GetFolder(server.MapPath(".")).Files

                  dim ext
                  ext = fso.GetExtensionName(fle.path)

                  if (ext <> "asp") and (ext <> "scc") then
                  %>
                  <tr>

                  <td class="FileName"> <a href='<%= escape(fle.Name) %>'><img src="/images/file.gif" width="14" height="16" border=0>
                  <%= fle.Name %></a></td>

                  <td class="FileSize">  <%= FormatSize(fle.Size) %></td>
                  <td class="FileDate"><div align="left">  <%= FormatDateTime(fle.DateLastModified,2) %></div></td>
                  </tr>
                  <%
                  end if

                  next
                  Set fso = Nothing
                  Set fle = Nothing
                  Set fldr = Nothing

                  %>
                  </table>
                  <p><a href="/index.asp">Return to Home Page</a></p>
                  • 6. Re: How can I display the date a word document was last modified on my web page?
                    Newsgroup_User Community Member
                    > but I would have to go to each individual file (I have hundreds) and put
                    > this
                    > code on each link.

                    can you use .net?

                    FYI, if you have a lot of files that need to be updated with some regularity
                    (as I'm guessing since you want last update data) you might want to look at
                    migrating this content into a content/document management system of some
                    sorts.

                    -Darrel