following is my code
just see and reply where is the code is wrong.
aspx code
code behind
protected void btSave_Click(object sender, EventArgs e)
{
try
{
noteFile = "";
/*File is existed or not cheked**/
if (FileUpload1.HasFile)
{
/*File Size Checked*/
if (FileUpload1.FileBytes.Length < 1024 * 1000)
{
/*File Type Checked*/
string fileType=Path.GetExtension(FileUpload1.FileName);
if (fileType == ".xls" || fileType == ".doc")
{
/*get the last 'noteID' and add 1 to noteID*/
dt.Clear();
dt = dConnect.noteInfo(0, "", "", "", "", "", "", "", "admin");
noteID = 0;
/*Check the file name if any singal gile is save then need to delete it*/
dt.Clear();
dt = dConnect.noteInfo(0, "", "", "", "", "", "", dt.Rows[0]["noteID"].ToString() + '_', "byAdminFile");
exceprionString = "";
exceprionString = dConnect.exceptionMessage();
if (dt.Rows.Count == 0 && exceprionString.Equals(""))
{
noteID = 1 + Convert.ToInt32(dt.Rows[0]["noteID"].ToString());
FileUpload1.SaveAs(Server.MapPath("~/note") + noteID.ToString() + '_' + FileUpload1.FileName);
noteFile = noteID.ToString() + '_' + FileUpload1.FileName;
}
else
{
noteFile = "";
SMS("Only One File Can Stor Per Note");
}
}
else
SMS("Only Word or Excel File Can Upload");
}
else
SMS("File Size Should Not More Than 1 MB");
}
else
{
noteFile = "";
SMS(FileUpload1.FileName.ToString());
}
}
catch (Exception ex)
{
throw ex;
}
}
always the first if condition is false
FileUplod.HashFile always false
Dorababu MekaPosted Aug 16, 2012, 4:44 AM
Vijay YadavPosted Aug 13, 2012, 6:58 AM
Please go through the link, http://forums.asp.net/p/1105208/1689084.aspx
Naresh AvariPosted Jul 30, 2012, 12:30 AM
Fileupload doesn't work for updatepanel. I got the same problem once.
1. Without updatepanel - it works fine
2. With updatepanel - you have to use postback trigger like this inside the update panel.
3. With updatepanel - You can use ASyncFileUploadControl in AJAX.
John BhattPosted Jul 28, 2012, 4:58 AM
Dadu DaPosted Jul 26, 2012, 12:22 AM
If I remove update panel then my code is work perfectly
Santhosh Kumar JayaramanPosted Jul 25, 2012, 4:41 AM
Dadu DaPosted Jul 25, 2012, 4:38 AM
if yes
then it is not work in visual studio 2008, which i use
I check that If I remove update panel the works properly but with update panel it is not work yet
Santhosh Kumar JayaramanPosted Jul 25, 2012, 3:07 AM
Dadu DaPosted Jul 25, 2012, 3:01 AM
but if i remove the update panel then i am able to get the file and save it successfully.
I want to use with update panel i see an examples but that also not work in my page
the examples I send with the post
InLine Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Pagetitle>
head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<table width="50%" cellpadding="2" cellspacing="0">
<tr>
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Upload" runat="server" Text="Upload" OnClick="Upload_Click" /><br />
<asp:Image ID="NormalImage" runat="server" />ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Upload" />
Triggers>
asp:UpdatePanel>
td>
tr>
table>
div>
form>
body>
html>
CodeBehind code:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Upload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(MapPath("~/Image/" + FileUpload1.FileName));
System.Drawing.Image img1 = System.Drawing.Image.FromFile(MapPath("~/image/") + FileUpload1.FileName);
NormalImage.ImageUrl = "~/Image/" + FileUpload1.FileName;
}
}
}
Santhosh Kumar JayaramanPosted Jul 25, 2012, 2:10 AM
Dadu DaPosted Jul 25, 2012, 2:08 AM
like followed
protected void note_Init(object sender, EventArgs e)
{
ScriptManager.GetCurrent(this).RegisterPostBackControl(FileUpload1);
}
FileUpload1 is ID of ASP:FileUpload
but Still i am unable to get the file
Santhosh Kumar JayaramanPosted Jul 25, 2012, 2:02 AM
Dadu DaPosted Jul 25, 2012, 2:00 AM
Sorry I wrote you name wrongly
I put File Upload in Update panel
please elaborate
Santhosh Kumar JayaramanPosted Jul 25, 2012, 1:44 AM
Check if you'r using a UpdatePanel, if so then in Page.Init do something like this:
Dadu DaPosted Jul 25, 2012, 1:42 AM
I do not get file thus how could i check the name of else
Santhosh Kumar JayaramanPosted Jul 25, 2012, 1:20 AM
{
try this
if (FileUpload1.FileName!=string.Empty)
{