I have a page that sends the value of a textbox in a form through GET.
My next page is supposed to grab that value, and put it in a variable. This is what I have for my next page:
1<%@dotnet.itags.org. Import namespace="System.IO"%>2<html>
3<head>
4<title>Uploading a File</title>
5678<script language="VB" runat="server">
9Dim strPath
10 strPath = Request.QueryString("path")
11
12 Dim savePath As String = StrPath
13Sub Upload_Click(source As Object, e As EventArgs)
1415 If Not (uploadedFile.PostedFile Is Nothing) Then
16 Try
17 Dim postedFile = uploadedFile.PostedFile
18 Dim filename As String = Path.GetFileName(postedFile.FileName)
19 Dim contentType As String = postedFile.ContentType
20 Dim contentLength As Integer = postedFile.ContentLength
2122 postedFile.SaveAs(savePath & filename)
23 message.Text = postedFile.Filename & " uploaded" & _
24 "<br>content type: " & contentType & _
25 "<br>content length: " & contentLength.ToString()
26 Catch exc As Exception
27 message.Text = "Failed uploading file"
28 End Try
29 End If
30End Sub
31</script>
32
33</head>
34<body>
35
36<form id="Form1" enctype="multipart/form-data" runat="server">
37 Select File to Upload:
3839 <input id="uploadedFile" type="file" runat="server">
40 <p>
41 <input type=button id="upload"
42 value="Upload"
43 OnServerClick="Upload_Click"
44 runat="server">
45 <p>
46 <asp:Label id="message" runat="server"/>
47</form>
48
49</body>
50</html>
I get a "declaration expected" on line 10. Any Ideas why?
A simle fix is to move both lines
Dim strPath as String = Request.QueryString("path")
Dim savePath As String = StrPath
to the top of Sub Upload_Click.
The actual error is that line 9 is not complete with a type declaration.
Dim strPathAs String
Also, you don't seem to need both strPath and savePath.
Dim savePath As String = Request.QueryString("path")
should be enough
Gunteman, I must respectfully disagree. If you put
Dim savePath As String = Request.QueryString("path")
outside of Sub Upload_Click, you get the following exception:
"Request is not available in this context."
However, removing strPath does make sense.
Thanks to both of you. I still got a problem even after doing that, but adding "Context." before "Request" cleared things up.
louis210:
Gunteman, I must respectfully disagree. If you put
Dim savePath As String = Request.QueryString("path")
outside of Sub Upload_Click, you get the following exception:
"Request is not available in this context."
Quite right!
0 comments:
Post a Comment