Hi ilanocf,
Please refer below sample.
HTML
<asp:FileUpload ID="fuUpload" runat="server"/>
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="UploadFile"/>
<hr />
<asp:Image ID="Image1" runat="server"/>
<asp:Label ID="lblMessege" runat="server"></asp:Label>
Namespace
C#
using System.IO;
VB.Net
Imports System.IO
Code
C#
protected void UploadFile(object sender, EventArgs e)
{
string folderPath = Server.MapPath("~/Files/");
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
if (!File.Exists(Server.MapPath("~/Files/") + Path.GetFileName(fuUpload.FileName)))
{
if (fuUpload.PostedFile.ContentLength < 102400)
{
fuUpload.SaveAs(folderPath + Path.GetFileName(fuUpload.FileName));
Image1.ImageUrl = "~/Files/" + Path.GetFileName(fuUpload.FileName);
}
else
{
lblMessege.Text = "File size of is exceeding the limit.";
}
}
else
{
lblMessege.Text = "File already exists.";
}
VB.Net
Protected Sub UploadFile(ByVal sender As Object, ByVal e As EventArgs)
Dim folderPath As String = Server.MapPath("~/Files/")
If Not Directory.Exists(folderPath) Then
Directory.CreateDirectory(folderPath)
End If
If Not File.Exists(Server.MapPath("~/Files/") + Path.GetFileName(fuUpload.FileName)) Then
If fuUpload.PostedFile.ContentLength < 102400 Then
fuUpload.SaveAs(folderPath & Path.GetFileName(fuUpload.FileName))
Image1.ImageUrl = "~/Files/" & Path.GetFileName(fuUpload.FileName)
Else
lblMessege.Text = "File size of is exceeding the limit."
End If
Else
lblMessege.Text = "File already exists."
End If
End Sub