PostedFile.SaveAs going to browse window automatically ???

J

jason

some confusion here.

The below code allows me to save a local file to my web server and
somehow because the field type is file a local file browse button is
rendered. I'm trying to figure out how to incorporate this code into
an existing asp.net (vb).

In my code "C:\Uploads\uploadedfile.txt" is dynamcially set to a value
pulled from a textbox, but how do automatically get browse window to
come up when I call a subroutine asp.net. Does asp.net have an
asp:file tag type? I'm looking to always select the local file via a
browse window, and don't want a local file field to be visible.

Thanks in advance!

<%@ Page Language="VB" %>
<script runat="server">

Sub SubmitButton_Click(Source As Object, e As EventArgs)
If Not (File1.PostedFile Is Nothing) Then
Try
File1.PostedFile.SaveAs("C:\Uploads\uploadedfile.txt")
Span1.InnerHtml = "Upload Successful!"
Catch ex As Exception
Span1.InnerHtml = "Error saving file <b>C:\\" & _
File1.Value & "</b><br>" & ex.ToString()
End Try
End If
End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server" enctype="multipart/form-data">
Select a file to upload:<br />
<input type="file" id="File1" runat="Server">
<p>
<input type="submit" id="Submit1" runat="Server"
value="Upload File" OnServerClick="SubmitButton_Click">
<p>
<span id="Span1" runat="Server" />
</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top