logsmanage.aspx.cs

来自「microsoft公司在进行ASP.NET 2.0培训课时课堂操作演示代码。」· CS 代码 · 共 75 行

CS
75
字号
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Xml;
public partial class Blogers_LogManage : System.Web.UI.Page
{
    private System.Drawing.Image.GetThumbnailImageAbort calltm = null;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        bool flag = false;
        
        if (this.FileUpload1.HasFile)
        {
            string path = Server.MapPath("~/XmlPic2/_pics");
            string[] fileexe ={".gif",".jpg",".png" };
            string myexe = System.IO.Path.GetExtension(this.FileUpload1.FileName);
            for (int i = 0; i < fileexe.Length;i++ )
            {
                if(fileexe[i]==myexe)
                {
                    flag = true;
                    break;
                }
            }
            if (flag)
            {
                this.FileUpload1.SaveAs(path + "\\" + System.DateTime.Now.ToString().Replace(":","")+this.FileUpload1.FileName);
               // Image1.ImageUrl = "../UpFiles/" + System.DateTime.Now.ToString().Replace(":","")+this.FileUpload1.FileName;
               // System.Drawing.Image oldImage = System.Drawing.Image.FromFile(path + "\\" + System.DateTime.Now.ToString().Replace(":", "") + this.FileUpload1.FileName);
             //   System.Drawing.Image newImage = oldImage.GetThumbnailImage(Int32.Parse(this.txtWidth.Text), Int32.Parse(this.txtHeight.Text), calltm, new IntPtr());
              //  newImage.Save(path + "\\small" + System.DateTime.Now.ToString().Replace(":", "") + this.FileUpload1.FileName);
             //   string savepath="UpFiles/" + System.DateTime.Now.ToString().Replace(":","")+this.FileUpload1.FileName;
              //  string savesmallpath = "UpFiles/small" + System.DateTime.Now.ToString().Replace(":", "") + this.FileUpload1.FileName;
               // oldImage.Dispose();
              //  newImage.Dispose();
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(Server.MapPath("~/XmlPic2/photos.xml"));
                XmlNode xd = xmldoc.SelectSingleNode("photos");
                XmlElement xe1 = xmldoc.CreateElement("photo");
                xe1.SetAttribute("desc", this.TextBox1.Text);
                xe1.SetAttribute("url", "_pic/" + System.DateTime.Now.ToString().Replace(":", "") + this.FileUpload1.FileName);
                xd.AppendChild(xe1);
                xmldoc.Save(Server.MapPath("~/XmlPic2/photos.xml"));
                //string constr = System.Configuration.ConfigurationManager.ConnectionStrings["NewsDBConnectionString"].ConnectionString;
                //SqlConnection Con = new SqlConnection(constr);
                //string Sql = "insert into PicImage (Picname,PicUrl) values('" + this.TextBox1.Text + "','" + savesmallpath + "')";
                //SqlCommand Cmd = new SqlCommand(Sql, Con);
                //Con.Open();
                //Cmd.ExecuteNonQuery();
                //Con.Close();
            }
            else
            {
                Response.Write("<script>alert('请选择图片文件再上传!')</script>");
            }
        }
        else
        {
            Response.Write("<script>alert('请选择文件再上传!')</script>");
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?