net上傳代碼
来源:互联网 发布:ionic2 node sass 编辑:程序博客网 时间:2024/06/06 19:26
界面設計:
一個DropDownList1 一個textbox按鈕 一個File1控件 一個botton
private void Button1_Click(object sender, System.EventArgs e)
{
if(this.File1.PostedFile.ContentLength==0)
{
this.Label1.Text="上傳失敗";
}
else
{
UpFile();
this.Label1.Text="上傳成功";
}
}
void UpFile()
{
// String FullFileName=this.File1.PostedFile.FileName;
// String FileName=FullFileName.Substring(FullFileName.LastIndexOf("//")+1);
//
// this.File1.PostedFile.SaveAs(Server.MapPath("file")+"//"+FileName);
// System.Data.SqlClient.SqlConnection s_conn = DB.CreateDB();
// System.Data.SqlClient.SqlCommand s_comm = new System.Data.SqlClient.SqlCommand();
// s_comm.Connection = s_conn;
//
// s_comm.CommandText = string.Format("insert into news (Newstime,NewsName,URL,redge) values ('{0}','{1}','{2}','{3}')",
// //DateTime.Now.ToString("yyyy/MM/dd"),
// (this.TextBox1.Text).ToString(),
// FileName, string.Format("file/{0}",FileName),this.DropDownList1.SelectedValue);
//
// s_conn.Open();
// s_comm.ExecuteNonQuery();
// s_conn.Close();
String FullFileName=this.File1.PostedFile.FileName;
String FileName=FullFileName.Substring(FullFileName.LastIndexOf("//")+1);
//int dd=Convert.ToInt32((this.DropDownList1.SelectedValue).ToString());
int dd=Convert.ToInt32((this.DropDownList1.SelectedIndex).ToString());
if(dd==1)
{
this.File1.PostedFile.SaveAs(Server.MapPath("file/file1")+"//"+FileName);
System.Data.SqlClient.SqlConnection s_conn = DB.CreateDB();
System.Data.SqlClient.SqlCommand s_comm = new System.Data.SqlClient.SqlCommand();
s_comm.Connection = s_conn;
s_comm.CommandText = string.Format("insert into news (Newstime,NewsName,URL,redge) values ('{0}','{1}','{2}','{3}')",
//DateTime.Now.ToString("yyyy/MM/dd"),
(this.TextBox1.Text).ToString(),
FileName, string.Format("file/file1/{0}",FileName),this.DropDownList1.SelectedValue);
s_conn.Open();
s_comm.ExecuteNonQuery();
s_conn.Close();
}
- net上傳代碼
- net上傳代碼
- .NET
- .net
- .net
- .NET
- .net
- .NET
- .net
- .net
- .net
- .NET
- .net
- .net
- .net
- .net
- .NET
- net
- LOTUS学习技巧 二
- 背景顏色css代碼
- lotus 服务器常用命令大全
- Lotus Domino服务器及其应用系统的高级管理
- jpeg 文档格式
- net上傳代碼
- LOTUS学习技巧 三
- dataGuid數據綁定及其分頁
- 連接方法
- botton插入數據
- DropDownList1實現傳值再DataGuid中
- 水晶報表的綁定
- (爆笑)国产电视剧的电脑高手
- Microsoft Access 名字的由来(Where did the name for Microsoft Access come from?)