为什么用FileUpload上传图片到指定的文件目录下面,显示的是空文件?
protectedvoidbtnSave_Click(objectsender,EventArgse){stringimgurls="";stringfilePaths=...
protected void btnSave_Click(object sender, EventArgs e)
{
string imgurls = "";
string filePaths = "";
string filetype = this.FileUpload2.PostedFile.ContentType;
if (this.FileUpload2.HasFile == true)
{
filePaths = "wuliaoimg/" + 分类BLL.Authentication(this.FileUpload2.FileName);
if (filetype != "image/gif" && filetype != "image/bmp" && filetype != "image/JPG"
&& filetype != "image/jpg" && filetype != "image/jpeg" && filetype != "image/pjpeg" && filetype != "image/x-png")
{this.ScriptHelper.Alert("上传类型错误");
return;
}
else
{imgurls = filePaths;
ImgListAdd(this.FileUpload2.FileName, imgurls);
ProductIconHelper.Execute(imgurls, BioErpBLL.Util.ProductIconHelper.AdvertisingType.Gif_Drawing, this.FileUpload2.PostedFile);
}}}
protected Dictionary<int, MyUploadFile> ImgList
{
get
{Dictionary<int, MyUploadFile> result = ViewState["ImgList"] as Dictionary<int, MyUploadFile>;
if (result == null)
{result = new Dictionary<int, MyUploadFile>();
ViewState["ImgList"] = result;
} return result;
} }
protected void ImgListAdd(string fileName, string dataBaseFileName)
{ this.ImgList.Add(this.MyIdentity, new MyUploadFile(fileName, dataBaseFileName)); }
//调用代码this.FileUpload2.PostedFile.SaveAs(Server.MapPath(this.ImgList[s].DataBaseFileName)); 展开
{
string imgurls = "";
string filePaths = "";
string filetype = this.FileUpload2.PostedFile.ContentType;
if (this.FileUpload2.HasFile == true)
{
filePaths = "wuliaoimg/" + 分类BLL.Authentication(this.FileUpload2.FileName);
if (filetype != "image/gif" && filetype != "image/bmp" && filetype != "image/JPG"
&& filetype != "image/jpg" && filetype != "image/jpeg" && filetype != "image/pjpeg" && filetype != "image/x-png")
{this.ScriptHelper.Alert("上传类型错误");
return;
}
else
{imgurls = filePaths;
ImgListAdd(this.FileUpload2.FileName, imgurls);
ProductIconHelper.Execute(imgurls, BioErpBLL.Util.ProductIconHelper.AdvertisingType.Gif_Drawing, this.FileUpload2.PostedFile);
}}}
protected Dictionary<int, MyUploadFile> ImgList
{
get
{Dictionary<int, MyUploadFile> result = ViewState["ImgList"] as Dictionary<int, MyUploadFile>;
if (result == null)
{result = new Dictionary<int, MyUploadFile>();
ViewState["ImgList"] = result;
} return result;
} }
protected void ImgListAdd(string fileName, string dataBaseFileName)
{ this.ImgList.Add(this.MyIdentity, new MyUploadFile(fileName, dataBaseFileName)); }
//调用代码this.FileUpload2.PostedFile.SaveAs(Server.MapPath(this.ImgList[s].DataBaseFileName)); 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询