Пример #1
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        string RequestType  = flag.Text.ToString().Trim();
        string RequestTable = xc.SafeChar(Request["fTable"].Trim());
        string UpFileReturnStr;
        string insertIframeCode = string.Empty;
        string fileName         = uploadfile.FileName;

        if (RequestType.Equals("Img"))
        {
            if (WaterMark.Checked)
            {
                UpFileReturnStr = xc.UploadFile(uploadfile, RequestType, true);
            }
            else
            {
                UpFileReturnStr = xc.UploadFile(uploadfile, RequestType, false);
            }
        }
        else
        {
            UpFileReturnStr = xc.UploadFile(uploadfile, RequestType, false);
        }

        if (UpFileReturnStr.Equals("上传成功"))
        {
            //插入数据库
            string insertName = Session["NewFile"].ToString();

            string dimStr = "@fileID,@fileFlag,@fileTable,@fileName,@PostDate,@AdminIP,@AdminID";

            string[] strValue = new string[7];
            strValue[0] = Session["upFileID"].ToString(); //上传图片文件名ID关联"
            strValue[1] = RequestType;
            strValue[2] = RequestTable;
            strValue[3] = insertName;
            strValue[4] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            strValue[5] = xc.GetIP();
            strValue[6] = xc.adminID;

            if (db.InsertUpdateDB("upFileName", dimStr, strValue, string.Empty).Equals("发布成功"))
            {
                UpFileReturnStr += " OK!";
            }
            else
            {
                UpFileReturnStr += " NO!";
            }

            switch (RequestType)
            {
            case "Img":
                insertIframeCode = @"<p><img alt='' src='" + xc.UploadFolder + insertName.Substring(5, 8) + "/" + insertName + "' /></p>";
                break;

            case "Flash":
                insertIframeCode = "<p><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0'><param name='quality' value='high' /><param name='movie' value='" + xc.UploadFolder + insertName.Substring(5, 8) + "/" + insertName + "' /><embed pluginspage='http://www.macromedia.com/go/getflashplayer' quality='high' src='" + xc.UploadFolder + insertName.Substring(5, 8) + "/" + insertName + "' type='application/x-shockwave-flash'></embed></object></p>";
                break;

            default:
                insertIframeCode = "<a target='_blank' href=" + xc.UploadFolder + insertName.Substring(5, 8) + "/" + insertName + ">" + insertName + "</a>";
                break;
            }
            insertIframeCode = insertIframeCode + "<p>&nbsp;</p>";

            ClientScriptManager cs = Page.ClientScript;
            cs.RegisterClientScriptBlock(this.GetType(), "ClientScriptBlock", "<script>parent.CKEDITOR.instances.txtContent.insertHtml(\"" + insertIframeCode + "\");</script>");

            lblinfo.Text = uploadfile.FileName.ToString() + "&nbsp;" + UpFileReturnStr;

            if (RequestType.Equals("Img"))
            {
                indexPicSet.Items.Add(new ListItem(insertName, insertName));
                preImage.Visible  = true;   //预览图
                delPreImg.Visible = true;   //删除图片
                preImage.ImageUrl = xc.UploadFolder.ToString() + insertName.Substring(5, 8) + "/" + insertName;
            }
        }
        else
        {
            lblinfo.Text = UpFileReturnStr;
        }
    }