[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Getting this function to work in ASP.NET VB?

Posted on 2004-11-17
4
Medium Priority
?
584 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:mcjimbo
  • 2
4 Comments
 
LVL 19

Expert Comment

by:peh803
ID: 12606507
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:

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

Good luck!
peh803
0
 
LVL 10

Expert Comment

by:lengreen
ID: 12606562
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
0
 

Author Comment

by:mcjimbo
ID: 12606587
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
0
 
LVL 10

Accepted Solution

by:
lengreen earned 520 total points
ID: 12606600
<script language="VB" runat="server">

response.write(getLastModified().toshortdatestring)
   
Function getLastModified() As DateTime
            Dim strFile
            Dim oFile
            Dim dtmLMod
            Dim dtmLModDate

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

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

            dtmLModDate = FormatDateTime(dtmLMod, 1)

            getLastModified = dtmLModDate
      End Function
</script>
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question