Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is the code to upload files on local system
I am using c# window application to upload files on local system....this code works on my asp.net project....but window application it shows some error

the error is
C#
Error	3	The type or namespace name 'HttpFileCollection' could not be found (are you missing a using directive or an assembly reference?)	D:\saravana\Spatiotemporal Approach\SourceMain\SourceMain\source_fileuploadtomaster.cs	52	13	SourceMain


this is the code to upload files

C#
private void btnupload_Click(object sender, EventArgs e)
        {
            HttpFileCollection uploads = HttpContext.Current.Request.Files;
            for (int i = 0; i < uploads.Count; i++)
            {
                HttpPostedFile upload = uploads[i];

                if (upload.ContentLength == 0)
                    continue;


                string c = System.IO.Path.GetFileName(upload.FileName);
                string filename = System.IO.Path.GetFileNameWithoutExtension(upload.FileName);
                string extension = System.IO.Path.GetExtension(upload.FileName);

                string nfilepath;
                nfilepath = "D:\\saravana\\Spatiotemporal Approach\\SourceMain\\source_uploadfiles\\" + c;
                try
                {
                    upload.SaveAs("D:\\saravana\\Spatiotemporal Approach\\SourceMain\\source_uploadfiles\\" + c);
                    //Span1.InnerHtml = "Upload(s) Successful.";


                }

                catch (Exception Exp)
                {
                    //Span1.InnerHtml = "Upload(s) FAILED.";
                    Exp.ToString();
                }
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "insert into filedetails(filename,filetype,filepath) values('" + filename + "','" + extension + "','" + nfilepath + "')";
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Uploaded suxcessfully");

                }
                if (con.State == ConnectionState.Open)

                    con.Close();

            }
        }
Posted

You probably did not reference the assembly "System.Web". It's bundled with .NET Framework, so it's in the GAC, referenced in a .NET tab of the window "Add Reference". The full name of the type is System.Web.HttpFileCollection, http://msdn.microsoft.com/en-us/library/system.web.httpfilecollection.aspx[^].

—SA
 
Share this answer
 
Comments
saravana__ 28-Feb-12 2:10am    
Thankyou verymuch
Sergey Alexandrovich Kryukov 28-Feb-12 12:34pm    
You are welcome.
Good luck, call again.
--SA
namespace is System.Web
 
Share this answer
 
Comments
saravana__ 28-Feb-12 1:13am    
I already use this namespace.....no use
Sergey Alexandrovich Kryukov 28-Feb-12 1:27am    
Well, then the assembly "System.Web.dll" is not referenced. Please see my answer.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900