
How to open files for read/write in .aspx
First, I'm hearing two terms thrown around that I don't understand the difference between: ASP.NET and VB.NET. Aren't active server pages written in VBScript, therefor .ASPX pages are written in VB.NET, right?
Also, where can I find a language reference. I can't believe there are people all around me, programming in this language, and I can't find a simple reference book or website! I don't want a book with lots of fat, I want something that's real straightforeward, like O'Reilley's "Javascript: the definitive guide" and "Dynamic HTML: the definitive reference".
Okay, now my real question: How do I open a file (as shown below in VBScript)? The first error I get is...
Compiler Error Message: BC30188: Expected either a variable, constant, Enum, Type, or procedural declaration.
Source Error:
Line 8: Dim ThisPage : ' this document
Line 9: '
Line 10: fsObject = Server.CreateObject("Scripting.FileSystemObject")
Line 11: ' --- parse path and file name ---
Line 12: x = InstrRev(Request.ServerVariables("PATH_TRANSLATED"),"\",-1,1)
Here's the relevant portion of a similar webpage (an active server page), where I enumerate the images in the current directory, and display them, as well as their path. The page I'm now trying to write is similar, but would have a DELETE checkbox and an UPLOAD button and textbox (INPUT TYPE="file") for each image, which would be shown in a table (as it is here). I need to use .ASPX, because .ASP doesn't (why I'll never understand) allow input type of file to be properly handled from a web form. All I want to do is accept the file if it's the correct type, deposit it in the current directory, then reload the page, showing the new image added in.
' --- find images ---
Dim Img(100,2) : ' allow up to 100 image files
Dim Hmny : ' how many images we have in this directory
set folder = fsObject.GetFolder(ThisPath)
For Each imageFile in Folder.Files
fileNam = fsObject.GetBaseName(imageFile)
fileExt = UCase(fsObject.GetExtensionName(imageFile))
Set fileAtr = fsObject.GetFile(imageFile)
fileDat = fileAtr.DateLastModified
fileSiz = fileAtr.Size
' -- we're only looking for image files (jpg, gif) --
If fileExt = "JPG" or fileExt = "GIF" Then
hmnyImages = hmnyImages + 1
Img(hmnyImages,0) = fileNam & "." & fileExt
Img(hmnyImages,1) = fileDat
Img(hmnyImages,2) = Int(fileSiz / 1024) & " kb"
End If
Next
...
<FORM NAME="f2">
<TABLE border=1>
<CAPTION ALIGN='center' STYLE="font-family:arial, sans-serif; font-size:10pt; font-weight:600">
IMAGES
</CAPTION>
<TR>
<%
y = 0 : ' cell counter so we go 5 across, then start on another <TR>
For x = 1 to hmnyImages
If y = 4 then
y = 0
Response.Write " </TR><TR>" & vbCrLf
End If
y = y + 1
fileNam = WebPath & "/" & Img(x,0)
Response.Write " <TD ALIGN='center'>"
Response.Write "<A HREF='" & fileNam & "' TARGET='_blank'>"
Response.Write "<IMG SRC='" & fileNam & "' HEIGHT=80 WIDTH=100 BORDER=0></A><BR>"
Response.Write "<INPUT NAME='IMAGE" & x & "' TYPE='text' SIZE='25' VALUE='" & fileNam & "'><BR>"
Response.Write Img(x,1) & " - " & Img(x,2) & "</TD>" & vbCrLf
Next
%>
</TR>
<TR>
<TD COLSPAN=4 ALIGN="center" VALIGN="bottom">
<BR>
<INPUT TYPE="BUTTON" NAME="f2Submit" VALUE="ADD / REMOVE IMAGES"
onClick="javascript:OpenImageLoader();">
</TD>
</TR>
</TABLE>
I've noticed other BS with vb.net (or asp.net or whatever you call it) such as the Response.Write must have parentheses around them, even though .asp is unconcerned with it. Grrr... it just makes the pages less portable when going from .asp to .aspx. Oh well.
-DM