根据员工ID显示图像 [英] Show image according to employee id

查看:65
本文介绍了根据员工ID显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用asp.net图片网址控件

我想根据员工ID显示图片。

一切正常,但图片只显示为图片网址中的十字标记(X)我选择id.please给我建议



我尝试过的事情:



string imgpath = Server.MapPath(〜/ image /+ FileUpload1.FileName);

string extension = Path.GetExtension(FileUpload1.PostedFile.FileName );

FileUpload1.SaveAs(uploadFolder +Test+ DropDownList1.SelectedItem.Text + extension);

Image1.ImageUrl =〜/+ imgpath;

ImageButton1.ImageUrl =〜/+ imgpath;

Labelupload.Text =文件成功上传为:+测试+扩展名;

i am using asp.net image url control
I want to display image according to employee id.
Everything is working fine but image is just displaying as Cross sign(X) in Image url wen I select id.please give me suggestion

What I have tried:

string imgpath = Server.MapPath("~/image/" + FileUpload1.FileName);
string extension = Path.GetExtension(FileUpload1.PostedFile.FileName);
FileUpload1.SaveAs(uploadFolder + "Test" + DropDownList1.SelectedItem.Text + extension);
Image1.ImageUrl = "~/" + imgpath;
ImageButton1.ImageUrl = "~/" + imgpath;
Labelupload.Text = "File uploaded successfully as: " + "Test" + extension;

推荐答案

从你的代码我可以看到保存的文件名和路径与image1.ImageUrl路径不同。这是因为行之间

From you code I can see that the saved file name and path will be different to the image1.ImageUrl path. This is because between the lines
string imgpath = Server.MapPath("~/image/" + FileUpload1.FileName);






and

Image1.ImageUrl = "~/" + imgpath;



你这样做:


you are doing this:

uploadFolder + "Test" + DropDownList1...



所以路径不同。



此外,此行是硬编码的,因此更改代码以显示正确构造的路径:


So the paths are different.

Also, this line is hardcoded so change the code to show the properly constructed path:

Labelupload.Text = "File uploaded successfully as: " + "Test" + extension;



更改为:


change to:

string saveTo = uploadFolder + "Test" + DropDownList1.SelectedItem.Text + extension;
Labelupload.Text = "File uploaded successfully as: " + saveTo;


string imgpath = Server.MapPath("~/image/" + FileUpload1.FileName);





这给出了服务器光盘上文件的位置,因此它将类似于c:\inetpub \wwwroot \yoursite \ imagesi \ image.jpg



这不是一个有效的图像源,因此您无法将其设置为图像的ImageUrl属性,这将导致图像URL为



/ images / c:\inetpub ....



这显然无法在客户端上运行。



您还可以将文件保存到完全不同的位置和文件名。



您的代码也有安全性问题,它允许我上传.aspx文件或exe文件,它们将保存到您的服务器。



无论如何,阅读一些有关上传和显示图像的文章,你会发现执行你想要做的事情的代码,你的代码都不正确。



This gives the location of the file on the server's disc, so it will be something like "c:\inetpub\wwwroot\yoursite\images\image.jpg"

That isn't a valid image source so you can't set it as the ImageUrl property of the image, it would result in an image url of

"/images/c:\inetpub...."

which is obviously not going to work on the client.

You also save the file to a completely different location and filename anyway.

Your code also has security problems, it allows me to upload .aspx files, or exe files and they'll be saved to your server.

Anyway, read some articles on uploading and showing images and you'll find code that does the kind of thing you're looking to do, none of your code is correct.


这篇关于根据员工ID显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆