Last post Sep 01, 2011 08:29 AM by TRIMS30
Aug 31, 2011 11:33 PM|TRIMS30|LINK
The following gives error on both Session() and Server.mappath() functions
Error is " "Cannot refer to an instance member of a class from within a shared method...."
Need to write some subroutines that can be called from other forms
See my code below.
Public Class CommonFunctions
Public Shared Sub GetPdfFile(ByVal FileIndex As String, ByVal Index As String)
Dim FILENAME As String = Server.MapPath("data\" & Session("Serial") & "\Command.txt")
Sep 01, 2011 01:02 AM|shabirhakim1|LINK
Hi I believe it is because of
Dim FILENAME As String Try to change above statement with below Private Shared FILENAME As String
Refer this article
Sep 01, 2011 01:18 AM|TRIMS30|LINK
Sorry, that's not the problem.
Any other ideas?
This is valid....
Public Sub MySub ()
This is not....
Public Shared Sub MySub ()
Sep 01, 2011 01:24 AM|Raja Boopathi|LINK
Session and Server properties are instance based. It cannot be accessed from a shared method.
Use HttpContext.Current property to access those properties.
Change below code
Sep 01, 2011 01:28 AM|shabirhakim1|LINK
Raja is right..
Sep 01, 2011 08:29 AM|TRIMS30|LINK