17 Aug 2018 
Support Center » Knowledgebase » How to Upload files using asp.net
 How to Upload files using asp.net
Solution

The following example demonstrates how to use the PostedFile property to initiate the utility that transfers the file to the server.

 
<SCRIPT language=VB runat="server">
   Sub Button1_Click(Source As Object, e As EventArgs)

      If Text1.Value = "" Then
         Span1.InnerHtml = "Error: you must enter a file name" Return
      End If

      If Not (File1.PostedFile Is Nothing) Then
         Try

            File1.PostedFile.SaveAs(("e:\userdirs\wwwroot\myusername" + Text1.Value))
            Span1.InnerHtml = "File uploaded successfully to <b>...\myusername" & _
               Text1.Value & "</b> on the Web server"
         Catch exc As Exception
            Span1.InnerHtml = "Error saving file <b>...\myusername" & _
               Text1.Value & "</b><br>" & exc.ToString()          End Try
      End If
   End Sub 'Button1_Click

</SCRIPT>
</P>
<H3>HtmlInputFile Sample</H3>

<P class=heading>
<FORM encType=multipart/form-data runat="server">
Select File to Upload:
<INPUT id=File1 type=file maxLength=30 runat="server">
</P> <BR>

<P>Save as filename (nopath): <INPUT id=Text1 runat="server"><BR>

<P><SPAN id=Span1 style="FONT:8pt verdana" runat="server"><BR>
<P><INPUT id=Button1 type=button value=Upload runat="server" OnServerClick="Button1_Click">
</FORM>



Article Details
Article ID: 9
Created On: 16 Aug 2006 03:17 AM

 This answer was helpful  This answer was not helpful

 Login [Lost Password] 
Email:
Password:
Remember Me:
 
 Search
 Article Options
Home | Register | Submit a Ticket | Knowledgebase | Troubleshooter | News | Downloads
Language:

Help Desk Software By Kayako SupportSuite v3.00.82