主营业务:网站制作 网站优化 小程序制作 石家庄网站制作网站建设有限公司欢迎您!
石家庄闪云网络科技有限公司
客服热线15383239821
如何让自己的网站更有质量?

FileUpload过滤文件类型

发布时间:2011/5/2 7:26:20

protected void btnSave_Click(object sender, EventArgs e)
        {
            // 确定文件夹
            string directory = WhichDirectory();
            StringBuilder str = new StringBuilder();

            if(FileUpload1.HasFile)
            {
                // 对上传文件的类型进行过滤,该处只能传压缩文件(rar或者zip),这种文件在火狐

                 浏览器中,叫application/octet-stream
               

                 if ((this.FileUpload1.PostedFile.ContentType == "application/x-zip-compressed")

                 || (this.FileUpload1.PostedFile.ContentType == "application/octet-stream"))
                {
                    try
                    {
                        str.AppendFormat("上传文件名: {0}", FileUpload1.FileName);

                        // 保存文件
                        string thefilepath = string.Format(HttpContext.Current.Server.MapPath(("~/

                         {0}/{1}/") FileUpload1.FileName), "资源", directory);
                        FileUpload1.SaveAs(thefilepath);

                        // 显示文件的信息
                        str.AppendFormat("<br />正在上传: {0}", FileUpload1.PostedFile.FileName);
                        str.AppendFormat("<br />文件类型: {0}",

            

在线客服 : 服务热线:15383239821 电子邮箱: 27535611@qq.com

公司地址:石家庄市新华区九中街江西大厦4062

备案号:冀ICP备2022000585号-4