Praveen Venugopal

Praveen Venugopal

  • NA
  • 127
  • 76.4k

Problem in Receiving the files that had been attached with my web form

Aug 23 2008 12:55 AM

Hello there!,

    I am having trouble in receiving the attached files from a html file input !.

First of all i have added a master  page and made this form as a content page!

Actaully the view state of this html file input is not maintaining when the page is posted back!.    It says Request.Files.Count=0 even i had attached a file!

Before adding the master page it worked fine!

  Could you please tell me a solution!,
My Code is

if (Request.Files.Count != 0)
        {
            HttpFileCollection files = Request.Files;
            DataTable Table4 = new DataTable();


            DataColumn Doc_Name = new DataColumn();
            Doc_Name.ColumnName = "Documents";

            DataColumn Remove = new DataColumn();
            Remove.ColumnName = "Remove";
 
            Table4.Columns.Add(Doc_Name);

            Table4.Columns.Add(Remove);
 for (int p = 0; p < files.Count; p++)
                {
                    HttpPostedFile file = files[p];

                    if (file.ContentLength == 0)
                    {
                        continue;
                    }
                    string c = System.IO.Path.GetFileName(String.Format(file.FileName));

                    string path = Server.MapPath("../")+"Upload"+ @"\" +c;
                                       

                    StreamWriter streamWriter;
                    streamWriter = File.CreateText(path);
                    streamWriter.Close();

                    file.SaveAs(path);

                    Table4.Rows.Add(p);
                                
                    Table4.Rows[p]["Documents"] =c;
                    Table4.Rows[p]["Remove"] = "Remove";

                   }
                Session["DOC_INFO"] = Table4;
}

 

 


Answers (2)