关于ASP.net上传图片
同一段代码,上传.txt文件是完好的,上传图片和.exe文件就只有一个空壳,没有内容的
这是我的代码:
string filepath = FileUpload1.PostedFile.FileName.ToString();
string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1);
string serverpath = HttpContext.Current.Server.MapPath("file/") + filename;
int pos = filename.LastIndexOf(".");
string lastname = filename.Substring(pos, filename.Length - pos);
FileUpload1.PostedFile.SaveAs(serverpath);
求指导,。。,
------解决方案-------------------- protected void pictureUpLoad_Click(object sender, EventArgs e)
{
//获取图片名称
string fileName = picUpload.FileName;
if (fileName != "")
{
//将图片名称都同意格式化yyyyMMddHHmmss+后缀
String randomStr = "Img" + DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
string lastName = randomStr + System.IO.Path.GetExtension(this.picUpload.FileName); //名字+后缀
//设置图片路径
string path = Server.MapPath("~/images/Joins/");
//保存图片
picUpload.SaveAs(path + lastName);
txtImage.Text = lastName;
}
else
{
ui.Alert(this, "不能上传空文件");
}
}
------解决方案--------------------我没有设定上传文件的大小
/// <summary>
/// 点击上传
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
&