Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
addnews2.cs
Package: Visual.rar [view]
Upload User: yiyuerguo
Upload Date: 2014-09-27
Package Size: 3781k
Code Size: 3k
Category:
CSharp
Development Platform:
Others
- using System;
- using System.Data;
- using System.Data.OleDb;
- using System.IO;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.HtmlControls;
- namespace www
- {
- public class MyCodeBehind : Page
- {
- public System.Web.UI.WebControls.DropDownList DropDownList2;
- public System.Web.UI.WebControls.TextBox biaoti;
- public System.Web.UI.WebControls.TextBox yinzi;
- public System.Web.UI.WebControls.TextBox neirong;
- public System.Web.UI.WebControls.TextBox zuozhe;
- public System.Web.UI.WebControls.Label Label1;
- public System.Web.UI.WebControls.Label Span1;
- public HtmlInputFile File1;
- public HtmlInputButton Button1;
- void Page_Load(Object sender, EventArgs e)
- {
- if(!IsPostBack)
- {
- OleDbConnection MyConnection =new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("candsql.mdb"));
- OleDbDataAdapter myCommand=new OleDbDataAdapter("SELECT id,typename FROM bb ",MyConnection);
- DataSet ds= new DataSet();
- myCommand.Fill(ds,"bb");
- DropDownList2.DataSource = ds.Tables["bb"].DefaultView;
- DropDownList2.DataTextField = "typename";
- DropDownList2.DataValueField = "id";
- DropDownList2.DataBind();
- }
- }
- public void Button1_Click(object Source, EventArgs e)
- {
- //创建一个上传文件路径字符串 把所有上传文件 存储到file文件夹中
- string filepath = Server.MapPath("file/"+Path.GetFileName (File1.PostedFile.FileName));
- if ((biaoti.Text=="")||(neirong.Text=="")||(zuozhe.Text==""))
- {
- Label1.Text="标题、内容、作者等不能为空!";
- }
- else if (biaoti.Text.Length>=50)
- {
- Label1.Text="你的标题太长了!";
- }
- //这里也可以上传别的文件 (不只是图片文件)
- //检查上传文件大小
- else if (File1.PostedFile.ContentLength>473600)
- {
- Span1.Text="上传的文件不能超过400kb";
- return;
- }
- //检查是否重名
- else if (File.Exists(filepath))
- {
- Span1.Text="上传文件重名,请改名后再上传!";
- return;
- }
- else
- {
- if(File1.PostedFile != null)
- try
- {
- File1.PostedFile.SaveAs(filepath);
- }
- catch (Exception exc)
- {
- Span1.Text = "保存文件时出错<b>" + filepath + "</b><br>"+ exc.ToString();
- }
- OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+ Server.MapPath("candsql.mdb"));
- OleDbCommand myCommand = new OleDbCommand("insert into aa (biaoti,yinzi,neirong,zuozhe,shijian,click,img,typeid) values ('" + biaoti.Text.ToString() + "','" + yinzi.Text.ToString() + "', '" + neirong.Text.ToString() + "','" + zuozhe.Text.ToString() + "','" + DateTime.Now.ToString() + "',0,'" + Path.GetFileName(File1.PostedFile.FileName) + "','" + DropDownList2.SelectedItem.Value+ "')" , myConnection);
- myCommand.Connection.Open();
- myCommand.ExecuteNonQuery();
- myCommand.Connection.Close();
- Response.Redirect("morenews4.aspx") ;
- }
- }
- public void reset_Click(Object sender,EventArgs e)
- {
- biaoti.Text="";
- neirong.Text="";
- zuozhe.Text="";
- yinzi.Text="";
- }
- }
- }