File Name in FileUpload control ?

Posted by .Netlearner under ASP.NET on 2/14/2013 | Points: 10 | Views : 3615 | Status : [Member] | Replies : 2
Hello All,

Am using a Fileupload control and a button. While Clicking on the button Filename in the Fileupload controls disappears!!?

I want to save the file while i click the upload button my code is as follows,

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BulkInsert.aspx.cs" Inherits="BulkInsert" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">


<asp:FileUpload id="FileUpload1" runat="server" Text="Upload" Width="225px" />
<asp:Button ID="Button1" runat="server" Text="Export" OnClick="btnUpload_Click" CausesValidation="false" />


</form>
</body>
</html>



if (!FileUpload1.HasFile)
{
string path = string.Concat(Server.MapPath("~/CSV/" + FileUpload1.FileName));
FileUpload1.SaveAs(path);
}





Responses

Posted by: Sireesha on: 2/14/2013 [Member] Starter | Points: 25

Up
0
Down
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Upload" onclick="Button1_Click" />
<br />
<br />
<br />
<asp:Label ID="uploadstatus" runat="server" Text="uploadstatus"></asp:Label>
</div>
</form>
</body>
</html>


protected void Button1_Click(object sender, EventArgs e)

{
string path = @"E:\Fileupload";
if (FileUpload1.HasFile)
{
string filename = FileUpload1.FileName;
path += filename;
uploadstatus.Text = "file uploaded successfully" + filename;
}
else
{
uploadstatus.Text = "file not uploaded";
}
}
}


A.Sireesha

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 2/15/2013 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this,
 

if (FileUpload1.HasFile)
{
string path = string.Concat(Server.MapPath("/CSV/" + FileUpload1.FileName));
FileUpload1.SaveAs(path);
string FName = System.IO.Path.GetFileNameWithoutExtension(FileUpload1.PostedFile.FileName);
Int32 FSize = FileUpload1.PostedFile.ContentLength / 1024;
Response.Write("<b>File Name :</b> " + FName);
Response.Write("<br/><b>File Size :</b> " + FSize +" KB");
}


Please Mark As Answer if this helps you...

.

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response