Dadu Da

Dadu Da

  • NA
  • 43
  • 34.6k

file uplod in asp.net with c#

Jul 25 2012 1:13 AM
I try many thing to upload file but unable to upload file
following is my code
just see and reply where is the code is wrong.

aspx code

<asp:FileUpload ID="FileUpload1" runat="server" width="100px"/>

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

Answers (16)