.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

FileUpload and UpdatePanel: FileUpload.HasFile is always FALSE.

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :ASP.Net
Hello. I'm developing an ASP.NET application with C# and Visual Studio 2008 SP1. I'm using WebForms. I have an ASPX page with two UpdatePanels, one on the left that holds a TreeView and other on the right where I load dynamically user controls. One user control, that I used on right panel, has a FileUpload control and a button to save that file on server. The ascx code to save control is:     <asp:UpdatePanel ID="UpdatePanelBotons" runat="server" RenderMode="Inline"      UpdateMode="Conditional">    <ContentTemplate>     <asp:Button ID="Save" runat="server" Text="Guardar"         onclick="Save_Click" CssClass="button" />     </ContentTemplate>     <Triggers>      <asp:PostBackTrigger ControlID="Save" />     </Triggers>    </asp:UpdatePanel> I make a full postback to upload the file to the server and save it to database. But I always getting False on FileUpload.HasFile. I problem is the right UpdatePanel. I need it to load dynamically the user controls. This panel has three UpdatePanels to load the three user controls that I

View Complete Post

More Related Resource Links

FileUpload.HasFile returns False

Hi everyone...I'm facing the following problem. I have an update panel where i have a multiview. One of the view is used to upload a file. I have a cmdUpload button. FileUpload.HasFile always returns false. I've read a few threads here about this issue and it is said that I have to add cmdUpload as a PostBack Trigger because Ajax does not allow Async uploads. I got an error by doing so that says that cmdUpload could not be registered neither as a PostBackTrigger nor as a AsyncPostbackTrigger due to  confilcts. What is really strange is that I remove from design code my updatePanel just to test it, and i'm still getting HasFile=false...I used this control before and never had a problem without an updatePanel.Any suggestion?Thanks!

UpdatePanel and FileUpload

Hi, i have wide customer table that i handle with a big DetailView nested inside an UpdatePanel for faster interaction. Works like a charm. Now they ask me to allow the user to upload a file, but when i add it in the detail view and i save data i get no file at all, as if putting it into an updatepanel do not allow him to send the file any more. Is there some setting i have to put so to make it work ? thanks in advance, Fabrizio

Problem in "Upload a picture into data base" because is in

Hi guys. I can upload a picture into database by this code correctly in a web page without "UpdatePanel": ******************************** SqlConnection connection = null; try { Byte[] imgByte = null; if (FileUpload.HasFile && FileUpload.PostedFile != null) { HttpPostedFile File = FileUpload.PostedFile; imgByte = new Byte[File.ContentLength]; File.InputStream.Read(imgByte, 0, File.ContentLength); } // Insert the employee name and image into db string conn = "Data Source=PC5;Initial Catalog=LaptopStore;Integrated Security=True"; connection = new SqlConnection(conn); connection.Open(); string sql = "INSERT INTO test(image) VALUES(@image) SELECT @@IDENTITY"; SqlCommand cmd = new SqlCommand(sql, connection); cmd.Parameters.AddWithValue("@image", imgByte); int id = Convert.ToInt32(cmd.ExecuteScalar()); lblResult.Text = String.Format("Employee ID is {0}", id); } catch { lblResult.Text = "There was an error"; } finally { connection.Close(); } ******************************************** But when I want to use this code in a

fileupload in UpdatePanel

Hi there, Can anybody tell me why this is working but not with UpdatePanel (commented lines here)?<body> <form id="form1" runat="server"> <div> <!--<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> --> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <br /> <!--<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate>--> <hr /> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> <asp:FileUpload ID="FileUpload1" runat="server" /><br /> <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label> <hr /> <!--</ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" /> </Triggers> </asp:UpdatePanel>--> <br /> <br /> <asp:Label ID="Label3" runat="server" Text="Label"></asp:Labe

FileUpload in DetailsView fails with UpdatePanel



I'm developing a project in ASP.NET C#, with SQL Server Express 2005, on Windows Vista.

I have a GridView, and a DetailsView on an aspx page.

The GridView displays all items in a database that has a certain ProductID (The items is Pictures)

The DetailsView displays the selected row of the GridView.

In the DetailsView I have 3 FileUpload controls, for 3 different size of images.

My update functionallity works just fine. I catch the OnUpdating event of it's ObjectDataSource, and uses FindControl to get each FileUpload Control, and executes the FileUpload.SaveAs() method if the user provided a new Image.

My problem occurs when I want to Insert a new image. No matter what - all my FileUpload's HasFile property is always false.

I was trying different things, and then I removed the UpdatePanel from the page. That solved my problem, but I really want to use the UpdatePanel. What I found really strange is, that the code very much identic to the code for inserting, works fine when I'm updating.

I use kind of the same idea as provided in this: http://www.asp.net/Learn/DataAccess/tutorial56cs.aspx?tabid=63 article. I just have an UpdatePanel arround both the GridView and DetailsView.

Any ideas on what might be wrong?

FileUpload inside the UpdatePanel


I am  facing some problem when I am trying upload a file when fileUpload control is inside an UpdatePanel. As I am checking whether the file is selected or not before upload, I found every time the fileUpload's selected file is lost. What I guess, when I am clicking the upload button which is also the trigger for that updatePanel, is creating a async postback and the selected file is lost, but I dont think this problem is beyond solution.So, anybody please help me with some solution. Please ping here also if any follow up info needed for answering

thanks in advance

Server side validation of Fileupload control not working



I've tried this method in my code behind to try and validate that the Fileupload control has a file or not. I get the error message the the event "Server Validate" cannot be found. Can anyone tell why? Thanks.

Public Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate

' Get file name

        Dim uploadAvatar As FileUpload = DirectCast(AdvertisementForm.FindControl("uploadAvatar"), FileUpload)

        Dim UploadFileName As String = uploadAvatar.PostedFile.FileName

        If UploadFileName = "" Then
            ' There is no file selected
            args.IsValid = False
            Dim Extension As String = UploadFileName.Substring(UploadFileName.L

FileUpload Class SaveAs, how can you overwrite?

Hello all,

I'm trying to use 2.0 class, FileUpload. 
Namespace: System.Web.UI.WebControls
Class FileUpload

Anyway, in my code can save the file to the server

FileUpload1.SaveAs(SavePath + FileName)

Problem is I can't find a way to overwrite the file.  When I try and run the program again is says the file is already in use that a process has access to it.

Is thre a proper way to release control of whatever it grabbing hold of it?  In .Net I don't have to destroy my objects right?
Or is there a way to specificly overwrite the file? It seems that SaveAs does that.  Just trying to figure out why I can upload this text file, but sometimes only once and then I have to code in to check to see if it exists then rename it.

FileUpload error: Object reference error


I have a FormView with a FileUpload to upload an image in a database.

I keep getting an object reference error.(view code)

I am using this same script to upload the image to the database, but when I try to update the file upload I get the error.    

string strFilePath=Server.MapPath("\\images\\"+fupdImage.FileName);

        Byte[] image=null;
        HttpPostedFile imgVid=FileUpload.PostedFile;

        image=new Byte[imgVid.ContentLength];//Object reference not set to an instance of an object.

        if(FileUpload.HasFile) {
        string imageFile=FileUpload.PostedFile.FileName;
        int index=imageFile.LastIndexOf(".");
        string fileFormat=imageFile.Substring(index+1);


FileUpload.SaveAs is configured to require a rooted path. but "http:// --- is not a rooted path


Hi Friends

when i am uploading image to http://filepath i got the 

The FileUpload.SaveAs Method is configured to require a rooted path but http:// filepath is not a rooted path

my code is as follows

If (Fileupload.HasFile)


Dim filepath As String = http://filepath/

FileUpload.SaveAs(filepath & String.Format("datafield_{0}_b.jpg", textbox.Text))

End If

Please help me




FileUpload Access Denied


Hi all.

I have done much research on this and am still stumped.

I have a ASP.NET 2.0 application, running on Windows 2003 Server. IIS 6.0

I am using Windows authentication , and I am not using impersonization, and I set my trust levvel to full.

<authentication mode="Windows"/>

<identity impersonate="false"/>

<trust level="Full

FileUpload Control with membership and roles


Hi Everyone!

I'm pretty new to development using Microsoft technologies.

I'm trying to build a portal kind of an application in asp.net, in which one of the functionality is letting people log in and upload their documents. The upload page is only accessible to registered users of the portal.


I would like to track the user uploaded files according to their userIds.

Is it possible to use the FileUpload Control and C# to fetch the current user id, create a directory with the same name(as that of userID) in the file system and upload the files( multiple file upload, if necessary) into it?

Also another admin page would have to be able to see the list of files uploaded by the specific user and download it if necessary.

Could anyone help me with this?

I'm also expecting alternate solutions to the problem.

Awaiting a response.

Thanks in advance 


Getting an error using FileUpload Control on a server.

Hello FriendsI m getting a problem while executing the following code for my website.This code works perfactly on localhost but when I use d same code on my webpage on the server it does nothing...even it doesnt return any error msg.Plz help me...protected void BtnUpload_Click(object sender, EventArgs e) {        int intFileSizeLimit = 1000;               string strFileNameWithPath = FileUpload1.PostedFile.FileName;               string strExtensionName = System.IO.Path.GetExtension(strFileNameWithPath);              string strFileName = System.IO.Path.GetFileName(strFileNameWithPath);           int intFileSize = FileUpload1.PostedFile.ContentLength / 1024;                              strExtensionName = strExtensionName.ToLower();        if (strExtensionName.Equals(".doc") || strExtensionName.Equals(".txt") || strExtensionName.Equals(".docx"))        {      

few questions about fileupload control

hey im currently using this to save pictures to a certin folderImgUpload.SaveAs(Server.MapPath("../Img/") + ImgUpload.FileName); my questions is 1. how do i avoid rewriting an image, in other words how do i check if there is another file using the same name? 2. how do i iterate on each image in the folder so that i can print certin html code for each img like for each image print this -> (<img src="Image_Path/Image-name.jpg/gif" width="?" height="?">   tnx

GridView EditItem FileUpload validation

Hey allI am using a gridview that contains an asp:fileupload so that when the user clicks 'edit' they can upload a pdf. I need to validate the size of the file, it needs to be less then a certain size. I tried to use a custom validator, but it never get called when the user updates. Is there a way to do this? How can I validate the file size on edit in the gridview?Thank youAaron

Using FileUpload and GridView controls

Hi to all,I have four controls in my page: FileUpload, LinkButton, GridView, and Button.FileUpload - I use the control to browse and open an Excel file in the client machine.LinkButton - I use the control to trigger the method that copies the Excel file to the server, converts the data of Excel file to DataTable, deletes the Excel file, and returns the DataTable.GridView - I use the control to display the data.Button - I use the control to save the data to the database.I did not see any problem until I uploaded the third file that hanged my page. I noticed that every time I upload a file, the page become slower gradually.Each Excel file has 2,000 records, and every time the GridView displays an item, it searches the data on the database. I think, the more the data in the database, the slower the searches can be.To solve this problem, I set the AllowPaging property of GridView to true. The less displaying of items, the less searching of data can be. But, every time I change the page of GridView, I have to bind again the data to the GridView. In order to bind the data, FileUpload must contain the source file, but not because FileUpload frees the file when the page posts back. And I don't want the user browses the file every time he changes the page of GridView. That is very tedious.Does anyone have encountered this kind of problem? Please share us your solution.Your responses


i can successfully upload, view and load an excel file into my webapp then into my db.  However when i go to upload a second time i keep getting the following error msg: The process cannot access the file <myfilename> because it is being used by another process. Now before everyone starts telling me to use .Dispose.. I am, everywhere I can..and I've isolated it to just the using the view functionality as a test... once viewed (connected to xls sheet) then file becomes "locked" and doesn't seem to relese.  Below is the code.  I am looking for any advice on what I am missing to unlock and reupload. thanks I got this from 4guysfromrolla.com however they don't cover this issue i've encountered. ---gets my file  (notice the fileuploadexcel object is being disposed-bolded) Protected Sub upload(ByVal sender As Object, ByVal e As System.EventArgs)         Dim fname As String        fname = Session("usr").ToString & "_Xlimp.xls"         If FileUploadExcel.HasFile Then            Try                'alter path for your project       
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend