本文介绍了窗口应用程序中HttpFileCollection的命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在本地系统上上传文件的代码
我正在使用C#窗口应用程序在本地系统上上传文件....此代码在我的asp.net项目上有效..但是在窗口应用程序中显示了一些错误

错误是

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

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

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();

            }
        }

推荐答案



这篇关于窗口应用程序中HttpFileCollection的命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 05:05