图像同时上传和查看 [英] image uploading and viewing at the same time

查看:72
本文介绍了图像同时上传和查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上传了一个文件.和按钮以及页面上的图像.我想在单击上载按钮后立即显示图像.图像是同一页面.编码如下

I have one file upload. and button and a image on a page.I want to show the image as soon as upload button is clicked.the image is the same page.The coding is as follows

protected void Button1_Click(object sender, EventArgs e)
   {
       String fn1 = Guid.NewGuid() + FileUpload1.FileName.Substring(FileUpload1.FileName.LastIndexOf("."));
       String sp1 = Server.MapPath(".");
       sp1 += "\\" + fn1;
       FileUpload1.PostedFile.SaveAs(sp1);
       Image1.ImageUrl = sp1;
   }


它没有读取图像,但是图像图标出现在图像控件上.
我使用过小图片也都使用过大图片.
它没有显示任何内容


It is not reading the image but image icon comes on the image control.
I have used small images as well as large.
it is not showing anything

推荐答案

你好Aksh @ 169,

要在图像控件中显示上载的图像,您可以替换此行的最后一行:

Hello Aksh@169,

to show the uploaded image in the image control, you can replace you last line from this line :

Image1.ImageUrl = FileUpload1.PostedFile.FileName;



这将满足您的要求.


如果有帮助,请接受答案.

Anurag



This will do the bit you require.


Please accept answer if this was helpful.

Anurag


您可以在网页中上传图片后使用给定的代码显示图片.

you can use given code to display image just after upload image in your web page.

string path = Server.MapPath("./") + FileUpload1.PostedFile.FileName;
      FileUpload1.SaveAs(path);
      Image1.ImageUrl = "./" + FileUpload1.PostedFile.FileName;



:)



:)


这篇关于图像同时上传和查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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