会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
simon
博客园
首页
新随笔
联系
订阅
管理
一个Web文件上传的C#源代码
//
保存文件的路径,包括文件名
private
string
GetSavePath(
string
FileName)
{
string
path
=
Request.PhysicalApplicationPath
+
"
\\Link_Icon
"
;
return
path
+
"
\\
"
+
FileName;
}
private
bool
UpLoad()
//
上传图片
{
bool
flag
=
false
;
string
FileName
=
GetFileName(fileIcon.Value );
string
db
=
Request.PhysicalApplicationPath
+
"
\\#CommCcope.mdb
"
;
string
constr
=
"
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=
"
+
db;
OleDbConnection con
=
new
OleDbConnection (constr);
try
{
//
上传文件
string
SavePath
=
GetSavePath(FileName);
fileIcon .PostedFile.SaveAs (SavePath);
//
插入数据库
OleDbCommand com
=
new
OleDbCommand (
"
Insert into FriendLink(SiteName,DISPLAY,LINK) VALUES('
"
+
txtName.Text
+
"
','
"
+
FileName
+
"
','
"
+
txtLink.Text
+
"
')
"
,con);
con.Open ();
com.ExecuteNonQuery ();
con.Close ();
flag
=
true
;
}
catch
(Exception ex)
{
Label1 .Text
=
"
错误:
"
+
ex.Message ;
}
finally
{
if
(con.State
!=
0
)con.Dispose ();
}
return
flag;
}
posted on
2007-02-07 12:49
mbskys
阅读(
93
) 评论(
0
)
收藏
举报
刷新页面
返回顶部