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
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jul 24, 2012, 9:20 PM EDT
{
try this
if (FileUpload1.FileName!=string.Empty)
{
Dadu Da40 reputationPosted Jul 24, 2012, 9:42 PM EDT
I do not get file thus how could i check the name of else
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jul 24, 2012, 9:44 PM EDT
Check if you'r using a UpdatePanel, if so then in Page.Init do something like this:
protected void userView_Init(object sender, EventArgs e) { ScriptManager.GetCurrent(this).RegisterPostBackControl(uploadFileButton); }Dadu Da40 reputationPosted Jul 24, 2012, 10:00 PM EDT
Sorry I wrote you name wrongly
I put File Upload in Update panel
please elaborate
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jul 24, 2012, 10:02 PM EDT
Its just page_Init..Your aspx name there protected void Page_Init(object sender, EventArgs e) { ScriptManager.GetCurrent(this).RegisterPostBackControl(uploadFileButton); }Dadu Da40 reputationPosted Jul 24, 2012, 10:08 PM EDT
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 JayaramanRank #563 · 4.3K reputationPosted Jul 24, 2012, 10:10 PM EDT
Dadu Da40 reputationPosted Jul 24, 2012, 11:01 PM EDT
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 JayaramanRank #563 · 4.3K reputationPosted Jul 24, 2012, 11:07 PM EDT
Dadu Da40 reputationPosted Jul 25, 2012, 12:38 AM EDT
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 JayaramanRank #563 · 4.3K reputationPosted Jul 25, 2012, 12:41 AM EDT
Dadu Da40 reputationPosted Jul 25, 2012, 8:22 PM EDT
If I remove update panel then my code is work perfectly
John BhattRank #1,381 · 1.2K reputationPosted Jul 28, 2012, 12:58 AM EDT
Naresh AvariRank #2,678 · 520 reputationPosted Jul 29, 2012, 8:30 PM EDT
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.
Vijay YadavRank #1,637 · 943 reputationPosted Aug 13, 2012, 2:58 AM EDT
Please go through the link, http://forums.asp.net/p/1105208/1689084.aspx
Dorababu MekaRank #457 · 5.5K reputationPosted Aug 16, 2012, 12:44 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts