Get posted file's full name
FileUpload is an asp.net web server control which enable site users to select a file from their computer and
upload it to web server file system.
FileUpload control's PostedFile property allow us to get the underlying HttpPostedFile object for a file that is uploaded by using the FileUpload server control. this PostedFile property has few sub properties. those sub properties help us to get additional information about uploaded file.
PostedFile property's FileName property allow us to get the fully qualified name of the file on the client. FileName property value data type is System.String. this string represents the name of the client's file, including the directory path.
the following asp.net c# example code demonstrate us how can we get the posted file's full name programmatically at run time in an asp.net application.
FileUpload control's PostedFile property allow us to get the underlying HttpPostedFile object for a file that is uploaded by using the FileUpload server control. this PostedFile property has few sub properties. those sub properties help us to get additional information about uploaded file.
PostedFile property's FileName property allow us to get the fully qualified name of the file on the client. FileName property value data type is System.String. this string represents the name of the client's file, including the directory path.
the following asp.net c# example code demonstrate us how can we get the posted file's full name programmatically at run time in an asp.net application.
FileUploadPostedFileFullName.aspx
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
string uploadFolder = Request.PhysicalApplicationPath + "UploadHere\\";
FileUpload1.SaveAs(uploadFolder + FileUpload1.FileName);
Label1.Text = "Your file uploaded successfully!<br />Posted File Full Name: "
+ FileUpload1.PostedFile.FileName;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>asp.net FileUpload example: how to get posted file full name after upload a file</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Fuchsia">asp.net FileUpload example: Posted File Name</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Size="Larger"
Font-Italic="true"
Font-Bold="true"
ForeColor="SeaGreen"
>
</asp:Label>
<br /><br />
<asp:Label
ID="Label2"
runat="server"
ForeColor="Crimson"
Text="Select a file for upload."
Font-Bold="true"
>
</asp:Label>
<br />
<asp:FileUpload
ID="FileUpload1"
runat="server"
BackColor="Crimson"
ForeColor="AliceBlue"
/>
<asp:Button
ID="Button1"
runat="server"
Font-Bold="true"
ForeColor="Crimson"
OnClick="Button1_Click"
Text="Upload This"
/>
<br /><br />
</div>
</form>
</body>
</html>



- asp.net FileUpload example: how to upload file with specific extension
- asp.net FileUpload validation example: how to validate FileUpload control (file upload)
- asp.net FileUpload example: how to check whether FileUpload control has file
- asp.net FileUpload example: how to check (handle) error when upload a file
- asp.net FileUpload example: how to get posted file content length (size) after upload file
- asp.net FileUpload example: how to get posted file content type after upload file
- asp.net FileUpload example: how to rename file when upload (change file name when upload)
- FileUpload example: how to use FileUpload control in asp.net