图像上传工作在视觉工作室但不是我发布时 [英] image uploading working in visual studio but not when i publish
本文介绍了图像上传工作在视觉工作室但不是我发布时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用图像control.its正在上传图片工作并上传图片但是当我在visual studio中运行时它工作正常,但是当我发布它时保存图像但没有显示..
cant undertnad为什么会发生..
请帮帮我
i'm using to upload an image using image control.its is working and uploading image but when i run in visual studio its work good but when i publish it is saving image but not showing..
cant understnad why it is happening..
please help me
protected void Page_Load(object sender, EventArgs e)
{
//Session.Timeout = 90;
string username = (string)(Session["UserAuthentication"]);
if(Session["UserAuthentication"]!=null)
{
Label2.Text=username;
Image1.ImageUrl = "Images/" + username;
}
private void StartUpLoad()
{
//get the file name of the posted image
string username = (string)(Session["UserAuthentication"]);
string imgName = username;
//sets the image path
string imgPath = "Images/" + imgName;
//get the size in bytes that
int imgSize = FileUpload1.PostedFile.ContentLength;
//validates the posted file before saving
if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
{
// 10240 KB means 10MB, You can change the value based on your requirement
if (FileUpload1.PostedFile.ContentLength > 1024000)
{
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('File is too big.')", true);
}
else
{
//then save it to the Folder
FileUpload1.SaveAs(Server.MapPath(imgPath));
Image1.ImageUrl = "~/images/"+imgName;
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Image saved!')", true);
}
}
protected void Button2_Click1(object sender, EventArgs e)
{
StartUpLoad();
}
推荐答案
使用以下StartUpload()方法
Use below StartUpload() Method
private void StartUpLoad()
{
//get the file name of the posted image
string username = (string)(Session["UserAuthentication"]);
//get the size in bytes that
int imgSize = FileUpload1.PostedFile.ContentLength;
//validates the posted file before saving
if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
{
// 10240 KB means 10MB, You can change the value based on your requirement
if (FileUpload1.PostedFile.ContentLength > 1024000)
{
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('File is too big.')", true);
}
else
{
//then save it to the Folder
string[] splitter = FileUpload1.PostedFile.FileName.Split('.');
string filePath = "Images/" + username +"." + splitter[1].ToString();
FileUpload1.SaveAs(Server.MapPath(filePath));
Image1.ImageUrl = "~/" + filePath;
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Image saved!')", true);
}
}
这篇关于图像上传工作在视觉工作室但不是我发布时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文