PostedFile is coming NULL, Iam uploading the file then also coming NULL [Resolved]

Posted by Amatya under C# on 3/14/2016 | Points: 10 | Views : 1225 | Status : [Member] | Replies : 3
<input id="UpBattery" runat="server" style="width: 286px" type="file" visible="false" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Upload" Visible="False" />


Here is my .cs file,(UpBattery.PostedFile is coming NULL.

protected void Button1_Click(object sender, EventArgs e)
{
DataTable dtgridstc = (DataTable)ViewState["GridTab"];
DataTable dtGrid = dtgridstc.Clone();
lblError.Text = "";
lblSuccess.Text = "";
try
{
if (UpBattery.PostedFile.FileName.Length >= 1)
{
HttpPostedFile excelFile = UpBattery.PostedFile;
if (excelFile.FileName.ToUpper().EndsWith(".XLS") == false)
{
lblError.Visible = true;
lblError.Text = "This is not a valid Battery Details File[Not an MS Excel File]";
return;
}


Help as soon as possible
Thanks in Advance

Feel free to share informations.
mail Id ' adityagupta200@gmail.com
Thanks



Responses

Posted by: Sheonarayan on: 3/14/2016 [Administrator] HonoraryPlatinum | Points: 50

Up
0
Down

Resolved
Here are some change

1. Instead of checking for PostedFile property, check for UpBattery.HasFile property to know whether the file has been selected.

2. Use FileUpload1.FileName directly to get the file name. Do not use PostedFile.

Looks like in the recent version, MS has done some changes, and PostedFile doesn't work as expected.

Hope this helps.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

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

Posted by: Amatya on: 3/16/2016 [Member] Silver | Points: 25

Up
0
Down
Then also its not working SheoNarayan Sir.

Feel free to share informations.
mail Id ' adityagupta200@gmail.com
Thanks

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

Posted by: Amatya on: 3/16/2016 [Member] Silver | Points: 25

Up
0
Down
Its solved sir, actually the code was in Update Panel, I removed update panel and now its working.


Feel free to share informations.
mail Id ' adityagupta200@gmail.com
Thanks

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

Login to post response