FileUpload

ASPX Page Code:

<asp:FileUpLoad id=”FileUpLoad” runat=”server” />

Add Regular expression to validate file extention.

<asp:RegularExpressionValidator
id=”FileUpLoadValidator” runat=”server”
ErrorMessage=”Upload Jpegs and Gifs only.”
ValidationExpression=”^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.jpg|.JPG|.gif|.GIF)$”

ControlToValidate
=”FileUpload”>
</asp:RegularExpressionValidator>

<asp:Button id=”UploadBtn” Text=”Upload File” OnClick=”UploadBtn_Click” runat=”server” Width=”105px” />

 

Code behind :

protected void UploadBtn_Click(object sender, EventArgs e)
{
if
(FileUpLoad1.HasFile)
{

FileUpLoad1.SaveAs(@”C:\temp\” + FileUpLoad1.FileName);
Label1.Text =
“File Uploaded: “
+ FileUpLoad1.FileName ;
}
else
{
Label1.Text =
“No File Uploaded.”
;
}
}

 

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s