温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:洪病毒单用户Blog系统源码
当前文件:
HBDBlog/Admin/AddVideo.aspx.cs[2K,2009-6-12 11:43:44],打开代码结构图
HBDBlog/Admin/AddVideo.aspx.cs[2K,2009-6-12 11:43:44],打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using System.Data.SqlClient; 12
13
public partial class Admin_AddVideo : System.Web.UI.Page 14
{ 15
protected void Page_Load(object sender, EventArgs e) 16
{ 17
18
} 19
protected void btn_add_Click(object sender, EventArgs e) 20
{ 21
if (Page.IsValid) 22
{ 23
Boolean fileOK = false; 24
String path = Server.MapPath("~/Video/"); 25
if (FileUpload1.HasFile) 26
{ 27
String fileExtension = 28
System.IO.Path.GetExtension(FileUpload1.FileName).ToLower(); 29
String[] allowedExtensions = 30
{ ".avi", ".wmv" ,".wma",".mp3"}; 31
for (int i = 0; i < allowedExtensions.Length; i++) 32
{ 33
if (fileExtension == allowedExtensions[i]) 34
{ 35
fileOK = true; 36
} 37
} 38
} 39
40
if (fileOK) 41
{ 42
try 43
{ 44
FileUpload1.PostedFile.SaveAs(path 45
+ FileUpload1.FileName); 46
string picpath = "Video/" + FileUpload1.FileName; 47
string name = FileUpload1.FileName; 48
string dec = tbx_dec.Text; 49
DateTime date = DateTime.Now; 50
51
//读取数据库连接字符串 52
string settings = Convert.ToString(ConfigurationManager.ConnectionStrings["SqlServices"]); 53
//创建数据库连接 54
SqlConnection myconn = new SqlConnection(settings); 55
//打开数据库连接 56
myconn.Open(); 57
//查询SQL语句 58
string strsql = "insert into videos(Video_Name,Adddate,Video_Des,Video_Url)"; 59
strsql = strsql + "values ( '" + name + "','"; 60
strsql = strsql + date + "','" + dec + "','"; 61
strsql = strsql + picpath + "')"; 62
//创建数据库命令 63
SqlCommand mycmd = new SqlCommand(strsql, myconn); 64
//测试用语句 65
//Response.Write(strsql); 66
//Response.End(); 67
mycmd.ExecuteNonQuery(); 68
myconn.Close(); 69
Response.Redirect("VideoManage.aspx"); 70
71
} 72
catch (Exception ex) 73
{ 74
lbl_msg.Text = "上传出现问题"; 75
} 76
} 77
else 78
{ 79
lbl_msg.Text = "上传文件类型错误!."; 80
} 81
} 82
} 83
} 84






}
}