protected void ADMIN_FILEUPLOAD_BT_Click(object sender, EventArgs e)
{
String savePath = "C:\\Documents and Settings\\Dang\\My Documents\\Visual Studio 2008\\WebSites\\新闻发布系统\\Upload\\";
bool boolean = false;
string FileName="a";
string FilePath="b";
if (ADMIN_FileUpload1.HasFile)
{
String fileName = ADMIN_FileUpload1.FileName;
savePath += fileName;
ADMIN_FileUpload1.SaveAs(savePath);
FileName = fileName;
FilePath = savePath;
boolean = true;
}
else
{
Response.Write("<script language=javascript>alert('您没有选择一个文件进行上传!')</script>");
}
if (boolean) {
DBAccess DB = new DBAccess();
string strSql = " INSERT INTO Download (filepath, filename) VALUES ('"+FilePath+"', '"+FileName+"')";
DB.DealData(strSql);
Response.Write("<script language=javascript>alert('上传成功!')</script>");
}
}以上是我写的代码 可是 怎么也无法获取字符串 修改不了数据库
请大家帮忙解决一下
{
String savePath = "C:\\Documents and Settings\\Dang\\My Documents\\Visual Studio 2008\\WebSites\\新闻发布系统\\Upload\\";
bool boolean = false;
string FileName="a";
string FilePath="b";
if (ADMIN_FileUpload1.HasFile)
{
String fileName = ADMIN_FileUpload1.FileName;
savePath += fileName;
ADMIN_FileUpload1.SaveAs(savePath);
FileName = fileName;
FilePath = savePath;
boolean = true;
}
else
{
Response.Write("<script language=javascript>alert('您没有选择一个文件进行上传!')</script>");
}
if (boolean) {
DBAccess DB = new DBAccess();
string strSql = " INSERT INTO Download (filepath, filename) VALUES ('"+FilePath+"', '"+FileName+"')";
DB.DealData(strSql);
Response.Write("<script language=javascript>alert('上传成功!')</script>");
}
}以上是我写的代码 可是 怎么也无法获取字符串 修改不了数据库
请大家帮忙解决一下
解决方案 »
- 怎么把转成的byte数组再转成之前的文件?
- IIRF 如何写以下两种规则
- datagrid中,如何只显示数据库中的前15个字符
- <急>在.NET中,用户登录再退出时,安全性怎么考虑啊?
- asp程序是源码显示的,那么asp.net是否也源码显示。我怎么来保证自己的程序源码不被窃取
- 那位仁兄给我一份文件上传,下载的代码或组件呀?
- asp.net 和 asp 的session如何共享?
- 我的关于权限控制的一个概念版的解决方法,请批评指点。
- 这是用VB写的统计在线人数的例子,有几处不太懂,请指教!!!!
- 大家帮帮忙拉,知道那里有电子政务方面的软件买吗?
- 网页布局
- 把一个文件夹下所有文件用GridView显示出来
我是想把这些路径放到一个数据库中 然后在下载的时候直接通过数据库生成下载的文件的列表
if (FileUpload1.PostedFile.FileName != "")
{
try
{
string FlvPath = FileUpload1.PostedFile.FileName;
string FlvName = FlvPath.Substring(FlvPath.LastIndexOf("\\") + 1);
string FlvExtend = FlvPath.Substring(FlvPath.LastIndexOf(".") + 1);
if (!(FlvExtend == "flv"))
{
message.Text = "上传图片的格式不正确!";
return;
}
string ServerPath = Server.MapPath("flv/") + FlvName;
FileUpload1.PostedFile.SaveAs(ServerPath);
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["testConnectionString1"].ConnectionString);
con.Open();
SqlCommand com = new SqlCommand("insert into Video(VideoPath)values('" + FlvName + "')", con);
com.ExecuteNonQuery();
con.Close();
message.Text = "上传成功,图片名称为:" + FlvName;
}
catch (Exception se)
{
message.Text = se.ToString();
}
}
看看管不管用public void add()
{
//获取图片的基目录
string path = AppDomain.CurrentDomain.BaseDirectory;
//获得上传图片的名称
string imgname = imgUp.FileName.ToString();
string strFileName = this.imgUp.PostedFile.FileName;
string strfileType = strFileName.Substring(strFileName.LastIndexOf('.') + 1).ToLower(); if (imgUp.HasFile)
{
if (imgUp.PostedFile.ContentType.ToLower() == "image/gif" || imgUp.PostedFile.ContentType.ToLower() == "image/pjpeg" || imgUp.PostedFile.ContentType.ToLower() == "image/bmp")
{
string newFielName = DateTime.Now.Ticks.ToString() + "." + strfileType;
string strPath = Server.MapPath("/") + "ServerCenter\\admin\\Upload\\" + newFielName;
//调用缩略图构造方法
ImageClass imageClass = new ImageClass(imgUp.PostedFile.InputStream);
//调用缩略图方法
Boolean flag = imageClass.GetReducedImage(120, 110, strPath); if (flag == true)
{
string newImgFiel = DateTime.Now.Ticks.ToString() + "" + DateTime.Now.Ticks.ToString() + "." + strfileType;
string strNewPath = Server.MapPath("/") + "ServerCenter\\admin\\Upload\\";
//保存原始图片到指定路径
this.imgUp.SaveAs(strNewPath + newImgFiel);
//调用缩略图构造方法(大图片)
ImageClass NewImageClass = new ImageClass(imgUp.PostedFile.InputStream); string sql = "insert into SJ_LP values(@lp_mc,@lp_sl,@lp_tpdz,@lp_sjjz,@lp_jdjg,@lp_yhjg,@lp_ystp,@lp_bz)";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@lp_mc", TextBox1.Text.Trim());
cmd.Parameters.AddWithValue("@lp_sl", TextBox2.Text.Trim());
cmd.Parameters.AddWithValue("@lp_tpdz", @"admin\Upload\" + imgname);
cmd.Parameters.AddWithValue("@lp_ystp", @"admin\Upload\" + newImgFiel);
cmd.Parameters.AddWithValue("@lp_sjjz", double.Parse(TextBox4.Text.Trim()));
cmd.Parameters.AddWithValue("@lp_jdjg", TextBox5.Text.Trim());
cmd.Parameters.AddWithValue("@lp_yhjg", TextBox6.Text.Trim());
cmd.Parameters.AddWithValue("@lp_bz", Server.HtmlEncode(WebEditor1.Text));
conn.Open(); if (cmd.ExecuteNonQuery() > 0)
{
conn.Close();
Response.Write("<script>alert('添加成功!');</script>");
showgift();
}
else
{
Response.Write("<script>alert('添加失败!');</script>");
}
}
else
{
Response.Write("<script>alert('添加失败!');</script>");
}
}
else
{
Response.Write("<script>alert('服务器只允许上传gif、jpg、bmp格式的图片');</script>");
}
}
else
{
Response.Write("<script>alert('请选择图片');</script>");
}
}
或者是private void btnbuildurl_Click(object sender, EventArgs e)
{
FolderBrowserDialog f = new FolderBrowserDialog();
if (f.ShowDialog() == DialogResult.OK)
{
txtbuildurl.Text = f.SelectedPath;
}
}
{
String fileName = ADMIN_FileUpload1.FileName;
savePath += fileName;
ADMIN_FileUpload1.SaveAs(savePath);
FileName = fileName;
FilePath = savePath;
boolean = true;
if (boolean) {
DBAccess DB = new DBAccess();
string strSql = " INSERT INTO Download (filepath, filename) VALUES ('"+FilePath+"', '"+FileName+"')";
DB.DealData(strSql);
Response.Write(" <script language=javascript>alert('上传成功!') </script>");
} }
else
{
Response.Write(" <script language=javascript>alert('您没有选择一个文件进行上传!') </script>");
}
string Savepath = Server.MapPath("../../../UpFile/StaPhoto/");//目标存放路径,写相对路径
string fileName = FileUpload1.FileName;
只是 无法获取FileName 和FilePath两个字符串 我单个用Label.text尝试过 显示的是正确的 但是就是如上传参数的时候无法正确给Sql语句
我想问问是不是长传过程造成页面重新启动 使得参数丧失了?