上传本地文件

protected void btnUpline_Click(object sender, EventArgs e)
        {
            string savaPath = Server.MapPath("~/Software/");//目的位置
            string softName = FileUpload1.FileName;

            
            try
            {
                if (FileUpload1.HasFile)
                {
                    if (softName != (txtsofwareName.Text + ".zip"))
                    {
                        MessageBox.Show(this.Page, "请将文件名称设为“软件名称.zip的格式”");
                        return;
                    }
                    FileUpload1.PostedFile.SaveAs(savaPath+FileUpload1.FileName );
                    MessageBox.Show(this.Page, "恭喜,上传成功!");
                }
                else 
                {
                    MessageBox.Show(this.Page, "请选择文件!");
                    
                }
            }
            catch
            {
                MessageBox .Show(this.Page ,"上传失败,请检查文件名!");
            }

        }

保存

/// <summary>
        /// 保存按钮的单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            //判断各个输入框是否正确
            if (this.txtsofwareName.Text.Trim().Length == 0)
            {
                strErr += "软件名称不能为空!\\n";
            }
            if (this.txtsofwareIntroduction.Text.Trim().Length == 0)
            {
                strErr += "简介不能为空!\\n";
            }
            if (this.txtcomputerID.Text.Trim().Length == 0)
            {
                strErr += "可供下载此软件的连接不能为空!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }

            string sofwareName = this.txtsofwareName.Text;
            string sofwareIntroduction = this.txtsofwareIntroduction.Text;
            string computerID = this.txtcomputerID.Text;

            Entity.CommomSoftwareInfoEntity model = new Entity.CommomSoftwareInfoEntity();

            model.sofwareName = sofwareName;
            model.sofwareIntroduction = sofwareIntroduction;
            model.computerID = computerID;

            //进行判断是否已经有软件的记录
            BLL.CommomSoftwareInfoBLL bll = new BLL.CommomSoftwareInfoBLL();
            if (bll.ExistSoftwareName(model) == true)
            {
                Common.MessageBox.ShowAndRedirect(this, "对不起,此软件已有记录,不能添加!", "AddCommonSoftware.aspx");
                return;
            }
            bll.Add(model);
            Common.MessageBox.ShowAndRedirect(this, "保存成功!", "AddCommonSoftware.aspx");

        }

猜你喜欢

转载自lishuangzhe.iteye.com/blog/1975924