Link to home
Start Free TrialLog in
Avatar of mcjimbo
mcjimbo

asked on

Getting this function to work in ASP.NET VB?

Hi guys,

I wrote this function in ASP to get the and display the modified date of a file.

<%
Function getLastModified()
    Dim strFile
    Dim File,oFile
    Dim dtmLMod
    Dim dtmLModDate

    strFile = Request.ServerVariables("SCRIPT_NAME")
    strFile = Replace(strFile, "/", "\")
    strFile = Server.MapPath(strFile)

    Set File = Server.CreateObject("Scripting.FileSystemObject")

    Set oFile = File.GetFile(strFile)
    dtmLMod = oFile.DateLastModified
    Set oFile = Nothing
    Set File = Nothing

    dtmLModDate = FormatDateTime(dtmLMod, 1)

    getLastModified = dtmLModDate
End Function
%>

I thought it might be .NET compatible, so I did the following:

<script language="VB" runat="server">    
Function getLastModified()
    Dim strFile
    Dim File,oFile
    Dim dtmLMod
    Dim dtmLModDate

    strFile = Request.ServerVariables("SCRIPT_NAME")
    strFile = Replace(strFile, "/", "\")
    strFile = Server.MapPath(strFile)

    Set File = Server.CreateObject("Scripting.FileSystemObject")

    Set oFile = File.GetFile(strFile)
    dtmLMod = oFile.DateLastModified
    Set oFile = Nothing
    Set File = Nothing

    dtmLModDate = FormatDateTime(dtmLMod, 1)

    getLastModified = dtmLModDate
End Function
</script>

However i'm getting the followin error message:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30807: 'Let' and 'Set' assignment statements are no longer supported.

Source Error:



Line 13:     strFile = Server.MapPath(strFile)
Line 14:
Line 15:     Set File = Server.CreateObject("Scripting.FileSystemObject")
Line 16:
Line 17:     Set oFile = File.GetFile(strFile)



Can anyone shed any light on what I need to change to make this script work in .net?

Thanks in advance

James
Avatar of peh803
peh803
Flag of United States of America image

James:

Just in case you don't find the answer you're looking for here in the ASP forum, you can try posting this question in the ASP.NET forum:

https://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/

Good luck!
peh803
Avatar of lengreen
lengreen

Hi Try This

Dim File= Server.CreateObject("Scripting.FileSystemObject")
If File.FileExists(strFile) Then
  oFile = File.GetFile(strFile)
  dtmLMod= oFile.DateLastModified
End if

Set is no longer supported

cheers

Len
Avatar of mcjimbo

ASKER

Nope, didn't work. It must be said i'm a newbie to .net so if someone could walk me through this i'd appreciate it.

Thanks again

James
ASKER CERTIFIED SOLUTION
Avatar of lengreen
lengreen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial