Help - Search - Members - Calendar
Full Version: ASP VB.Net "Property" statement question
OverclockersClub Forums > Operating Systems & Software Support > Programmer's Corner
ClayMeow
I'm trying to implement a file upload system on our website, so I'm trying to implement FreeASPUpload to upload files from the FancyUpload interface.

Referencing the freeaspupload.asp file straight up yielded the following error "Statement cannot appear within a method body. End of method assumed."

So I changed the file to remove the <%%> brackets and instead surround it with <script runat="server" language="VB">...okay, all good on that point. But then I guess the .asp file was written in VB and not .Net, so I have to change various methods and whatnot (I'm not even sure if it'll work after I get everything changed...but I won't know until that point). One such change is the "Property" method, and I'm not sure how to convert it. Here is the initial code:

CODE
    Public Property Get Form(sIndex)
        Form = ""
        If FormElements.Exists(LCase(sIndex)) Then Form = FormElements.Item(LCase(sIndex))
    End Property

    Public Property Get Files()
        Files = UploadedFiles.Items
    End Property
    
    Public Property Get Exists(sIndex)
            Exists = false
            If FormElements.Exists(LCase(sIndex)) Then Exists = true
    End Property
        
    Public Property Get FileExists(sIndex)
        FileExists = false
            if UploadedFiles.Exists(LCase(sIndex)) then FileExists = true
    End Property
        
    Public Property Get chunkSize()
        chunkSize = internalChunkSize
    End Property

    Public Property Let chunkSize(sz)
        internalChunkSize = sz
    End Property


.Net doesn't use the Get, Let and Set commands the same way. Here's an example from MSDN:

CODE
    Public Property prop1() As String
        Get
            ' The Get property procedure is called when the value
            ' of a property is retrieved.
            Return propertyValue
        End Get
        Set(ByVal value As String)
            ' The Set property procedure is called when the value
            ' of a property is modified.  The value to be assigned
            ' is passed in the argument to Set.
            propertyValue = value
        End Set
    End Property


My problem is that I'm not sure how to convert one of the original codes to the "proper" .Net format seen in the second code block.

Anyone understand this?

Thanks.
AJW256
I never coded non .net VB but to me it looks like the original code contains only gets.

So for eg. the first property converted to .net:

CODE
Public Readonly Property Form(sIndex)
  Get
    Form = ""
    If FormElements.Exists(LCase(sIndex)) Then Form = FormElements.Item(LCase(sIndex))
  End Get
End Property


Think that's right.
ClayMeow
thank you...i'll try it out smile.gif
AJW256
Wait, how did u reference freeaspupload.asp? I think this is a much simpler problem than you are making it out to be.
ClayMeow
QUOTE (AJW256 @ May 28 2009, 01:18 PM) *
Wait, how did u reference freeaspupload.asp? I think this is a much simpler problem than you are making it out to be.

You're probably right...because now I'm encountering even more problems. I've got to be doing something wrong, but I'm just following how the example is calling things.

I have <!-- #include file="fancyupload/freeaspupload.asp" --> at the top of my page, before the html tag. Here is what their test file's code is (testuploader.asp):

CODE
<%@ Language=VBScript %>
<%
option explicit
Response.Expires = -1
Server.ScriptTimeout = 600
%>
<!-- #include file="freeaspupload.asp" -->
<%


' ****************************************************
' Change the value of the variable below to the pathname
' of a directory with write permissions, for example "C:\Inetpub\wwwroot"
  Dim uploadsDirVar
  uploadsDirVar = "C:\Inetpub\wwwroot\webshare\images\user_content"
' ****************************************************

' Note: this file uploadTester.asp is just an example to demonstrate
' the capabilities of the freeASPUpload.asp class. There are no plans
' to add any new features to uploadTester.asp itself. Feel free to add
' your own code. If you are building a content management system, you
' may also want to consider this script: http://www.webfilebrowser.com/

function OutputForm()
%>
    <form name="frmSend" method="POST" enctype="multipart/form-data" action="uploadTester.asp" onSubmit="return onSubmitForm();">
    <B>File names:</B><br>
    File 1: <input name="attach1" type="file" size=35><br>
    File 2: <input name="attach2" type="file" size=35><br>
    File 3: <input name="attach3" type="file" size=35><br>
    File 4: <input name="attach4" type="file" size=35><br>
    <br>
    <!-- These input elements are obviously optional and just included here for demonstration purposes -->
    <B>Additional fields (demo):</B><br>
    Enter a number: <input type="text" name="enter_a_number"><br>
    Checkbox values: <input type="checkbox" value="1" name="checkbox_values"> 1 &nbsp;&nbsp;<input type="checkbox" value="2" name="checkbox_values"> 2<br>
    Drop-down list (with multiple selection): <br>      
    <select name="list_values" class="TextBox" MULTIPLE>
        <option value='frist' > First</option>
        <option value='second' > Second</option>
        <option value='third' > Third</option>
    </select><br>
    <textarea rows="2" cols="20" name="t_area">Test text area</textarea><br>
    <!-- End of additional elements -->
    <input style="margin-top:4" type=submit value="Upload">
    </form>
<%
end function

function TestEnvironment()
    Dim fso, fileName, testFile, streamTest
    TestEnvironment = ""
    Set fso = Server.CreateObject("Scripting.FileSystemObject")
    if not fso.FolderExists(uploadsDirVar) then
        TestEnvironment = "<B>Folder " & uploadsDirVar & " does not exist.</B><br>The value of your uploadsDirVar is incorrect. Open uploadTester.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."
        exit function
    end if
    fileName = uploadsDirVar & "\test.txt"
    on error resume next
    Set testFile = fso.CreateTextFile(fileName, true)
    If Err.Number<>0 then
        TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have write permissions.</B><br>The value of your uploadsDirVar is incorrect. Open uploadTester.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."
        exit function
    end if
    Err.Clear
    testFile.Close
    fso.DeleteFile(fileName)
    If Err.Number<>0 then
        TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have delete permissions</B>, although it does have write permissions.<br>Change the permissions for IUSR_<I>computername</I> on this folder."
        exit function
    end if
    Err.Clear
    Set streamTest = Server.CreateObject("ADODB.Stream")
    If Err.Number<>0 then
        TestEnvironment = "<B>The ADODB object <I>Stream</I> is not available in your server.</B><br>Check the Requirements page for information about upgrading your ADODB libraries."
        exit function
    end if
    Set streamTest = Nothing
end function

function SaveFiles
    Dim Upload, fileName, fileSize, ks, i, fileKey

    Set Upload = New FreeASPUpload
    Upload.Save(uploadsDirVar)

    ' If something fails inside the script, but the exception is handled
    If Err.Number<>0 then Exit function

    SaveFiles = ""
    ks = Upload.UploadedFiles.keys
    if (UBound(ks) <> -1) then
        SaveFiles = "<B>Files uploaded:</B> "
        for each fileKey in Upload.UploadedFiles.keys
            SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B) "
        next
    else
        SaveFiles = "The file name specified in the upload form does not correspond to a valid file in the system."
    end if
    SaveFiles = SaveFiles & "<br>Enter a number = " & Upload.Form("enter_a_number") & "<br>"
    SaveFiles = SaveFiles & "Checkbox values = " & Upload.Form("checkbox_values") & "<br>"
    SaveFiles = SaveFiles & "List values = " & Upload.Form("list_values") & "<br>"
    SaveFiles = SaveFiles & "Text area = " & Upload.Form("t_area") & "<br>"
end function
%>

<HTML>
<HEAD>
<TITLE>Test Free ASP Upload 2.0</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
BODY {background-color: white;font-family:arial; font-size:12}
</style>
<script>
function onSubmitForm() {
    var formDOMObj = document.frmSend;
    if (formDOMObj.attach1.value == "" && formDOMObj.attach2.value == "" && formDOMObj.attach3.value == "" && formDOMObj.attach4.value == "" )
        alert("Please press the Browse button and pick a file.")
    else
        return true;
    return false;
}
</script>

</HEAD>

<BODY>

<br><br>
<div style="border-bottom: #A91905 2px solid;font-size:16">Upload files to your server</div>
<%
Dim diagnostics
if Request.ServerVariables("REQUEST_METHOD") <> "POST" then
    diagnostics = TestEnvironment()
    if diagnostics<>"" then
        response.write "<div style=""margin-left:20; margin-top:30; margin-right:30; margin-bottom:30;"">"
        response.write diagnostics
        response.write "<p>After you correct this problem, reload the page."
        response.write "</div>"
    else
        response.write "<div style=""margin-left:150"">"
        OutputForm()
        response.write "</div>"
    end if
else
    response.write "<div style=""margin-left:150"">"
    OutputForm()
    response.write SaveFiles()
    response.write "<br><br></div>"
end if

%>

<!-- Please support this free script by having a link to freeaspupload.net either in this page or somewhere else in your site. -->
<div style="border-bottom: #A91905 2px solid;font-size:10">Powered by <A HREF="http://www.freeaspupload.net/" style="color:black">Free ASP Upload</A></div>

<br><br>


</BODY>
</HTML>

I'm sure I'm missing something so simple, but I can't figure out why it works for the test page, but not when I try to implement it into our site, except that there are other included files and namespaces being imported that maybe something's conflicted...but i have this FIRST before anything else, and the error definitely stops on that:

CODE
Line 11: const DEFAULT_ASP_CHUNK_SIZE = 200000
Line 12:
Line 13: Class FreeASPUpload
Line 14:     Public UploadedFiles
Line 15:     Public FormElements
*Line 13 is the one highlighted as having the error.
AJW256
I'm a little lost.

I think you should leave the Free ASP Upload code alone for now. I think the error is in the part where you are trying to implement the class.

You may want to start off by modifying bits of the example, seen as you said it works ok.
ClayMeow
QUOTE (AJW256 @ May 28 2009, 03:16 PM) *
I'm a little lost.

I think you should leave the Free ASP Upload code alone for now. I think the error is in the part where you are trying to implement the class.

You may want to start off by modifying bits of the example, seen as you said it works ok.

Yeah, that's what I'm going to try and do...I've been thinking, and I don't need all our navigation bars and whatnot...if I can just add the company logo there, I think that'd be fine. I'm thinking it's possibly due to the test page language being "vbscript" and our pages typically being set at "vb"...although i took out that declaration, maybe it's in an include somewhere i'm missing. shrug.

Thanks for your help smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.