В дополнение к примеру, приведенному службой поддержки @dbFrameIT:
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Always" runat="server">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="UploadButton" runat="server" Text="Upload Selected File" OnClick="UploadButton_Click" />
<asp:Label ID="UploadDetails" runat="server" Text=""></asp:Label>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="UploadButton" />
</Triggers>
</asp:UpdatePanel>
ваш код (c #)
protected void UploadButton_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile == false)
{
UploadDetails.Text = "Please first select a file to upload...";
}
else
{
string FileName = FileUpload1.FileName;
UploadDetails.Text = string.Format(
@"Uploaded file: {0}<br />
File size (in bytes): {1:N0}<br />
Content-type: {2}",
FileName,
FileUpload1.FileBytes.Length,
FileUpload1.PostedFile.ContentType);
// Save the file
string filePath = Server.MapPath("~/Brochures/" + FileUpload1.FileName);
FileUpload1.SaveAs(filePath);
}
}