窗口应用程序中HttpFileCollection的命名空间 [英] namespace for HttpFileCollection in window application

查看:485
本文介绍了窗口应用程序中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();

            }
        }

推荐答案

您可能没有引用程序集"System.Web".它与.NET Framework捆绑在一起,因此在GAC中,在添加引用"窗口的.NET选项卡中引用.该类型的全名是System.Web.HttpFileCollection http://msdn.microsoft.com /en-us/library/system.web.httpfilecollection.aspx [ ^ ].

—SA
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


命名空间为System.Web


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆