Tuesday, September 12, 2006

File Upload form in ASP.NET

In the HTML:

[form Method="post" EncType="multipart/form-data" RunAt="Server" ID="Form1"]
[%-- The File upload Html control --%]
Select File To Process
[Input ID="MyFile" Type="file" RunAt="Server" NAME="MyFile" style="WIDTH: 376px; HEIGHT: 22px"
[%-- A button - when clicked the form is submitted and the
Upload_Click event handler is fired... --%]
[asp:Label id="lblResult" style="Z-INDEX: 103; LEFT: 16px; POSITION: absolute; TOP: 120px"
runat="server" Width="312px" Height="80px"][/asp:Label]
[Input Type="submit" Value="Go" OnServerClick="Upload_Click" RunAt="Server" ID="Submit1"

In the code :

public void Upload_Click(object Sender, EventArgs e)
string strPath;
// get the path into variable
strPath = MyFile.Value;

No comments: