string Path = FileUpload.PostedFile.FileName;
string PictureName1 = FileUpload.FileName;
Load = Server.MapPath("~/UpLoad/") + PictureName1;
FileUpload.PostedFile.SaveAs(Load);
想做一个图片上传功能
但貌似运行时有问题 不知道哪错了 求解
想知道 这里的代码有啥问题
string PictureName1 = FileUpload.FileName;
Load = Server.MapPath("~/UpLoad/") + PictureName1;
FileUpload.PostedFile.SaveAs(Load);
想做一个图片上传功能
但貌似运行时有问题 不知道哪错了 求解
想知道 这里的代码有啥问题
解决方案 »
- 关于手机短信提示的实现??该怎么搞。?
- VS2010里怎么定时发生某个按钮的事件
- 怎么把as.net页面上的所有东西导出到PDF?(即把HTML转换为PDF)
- 下面的代码将标签中 my属性值放入标签innerText中,提示错误,是什么原因??
- 获取不到此图片和高度和宽度,是我代码的问题,还是控件的问题?:(
- SqlDataSource这样动态的改变SqlDataSource1.SelectCommand,SqlDataSource1.UpdateCommand...
- [Petshop问题]Category.aspx上明明是放一继承自Repeater的SimplePager控件,那为什么他在Category.aspx.cs里出现DataGridPageChangedEven
- datagrid里的绑定列为何没有ID属性呀!!我不想在后台自动生成。
- 请问如何在sqlcommand中写sql语句新建存储过程?
- WebForm能够从另一个WebForm继承吗,像WinForm一样?
- 请问下iis7.5中怎么配置伪静态
- vs2005关于遮罩层显示数据,并可以回传数据的问题
//其他一些后缀名或为空的自己判断下
string path = Server.MapPath("images/");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
string filename = path + Path.GetFileName(FileUpload1.FileName);
FileUpload1.SaveAs(filename);
FileUpload.SaveAs(Load);
这里首先要你的UpLoad文件夹是存在的才行。你再仔细看下
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
string name = FileUpload1.FileName;//上传文件名字
string size = FileUpload1.PostedFile.ContentLength.ToString();
string type = FileUpload1.PostedFile.ContentType;
string type2 = name.Substring(name.LastIndexOf(".") + 1);
string ipath = Server.MapPath("upimg") + "\\" + name;
string fpath = Server.MapPath("upfile") + "\\" + name;
string path="F:\\aaa\\"+FileUpload1.FileName;
string wpath = "upimg\\" + name;
if (type2 == "jpg" || type2 == "gif" || type2 == "bmp" || type2 == "png")
{
FileUpload1.SaveAs("F:\\aaa\\"+FileUpload1.FileName);
// Image1.ImageUrl="F:\\aaa\\"+FileUpload1.FileName;
Label1.Text = "你传图片的名字是" + name + "<br>文件大小为" + size + "<br>文件类型为" + type2 + "<br>文件路径为" + ipath;
}
SqlConnection cn = new SqlConnection("server=.;database=Northwind;uid=sa;pwd=sa");
SqlCommand cmd = new SqlCommand("insert into Image(imageName,imagepath) values('" + name + "','" + path + "')", cn);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{ SqlConnection cn = new SqlConnection("server=.;database=Northwind;uid=sa;pwd=sa");
SqlCommand cmd = new SqlCommand("select imageName from Image where imageID='" + Convert.ToInt32(TextBox1.Text) + "'", cn);
cn.Open();
string a = cmd.ExecuteScalar().ToString();
cn.Close();
Image1.ImageUrl = "F:\\aaa\\" + a;
}
}
string PictureName1 = FileUpload1.FileName;
string Load = Server.MapPath("~/UpLoad/") + PictureName1;
FileUpload1.PostedFile.SaveAs(Load);