my question is that how can i immediately display the server-side uploaded image [image being uploaded at a button click] ?
upload done using fileupload control.
image retrieval expected using image control.
below is the part of my code.
protected void Button1_Click(object sender, EventArgs e)
{
if(FileUpload1.HasFile)
FileUpload1.SaveAs(Server.MapPath("uploaded images/"+FileUpload1.FileName));
}
this code successfully uploads the image to "uploaded images" folder in the server.
but i failed to retrieve it to display as soon as it is uploaded.
below is what i tried, which never gave any programming error, though it never gave the
result too!
Image1.ImageUrl = (System.IO.Path.GetFileName(FileUpload1.FileName)).ToString();
help expected.
regards.
You really shouldn't assign local pathname as source for uploaded image.
Try something like
Image1.ImageUrl = "uploaded images/"+FileUpload1.FileName;
string imgPath = this.ResolveUrl("~/uploaded images/" + FileUpload1.FileName");
Image1.ImageUrl = imgPath;
Here's a full discussion of ASP.NET and image path issues.
Related
Using AJAX 4 (latest version) I have been working with the html editor extender trying to upload images with text, I have got the Image to upload however it appears blank and when looking at the source, the source of the image is also blank (image below) how do I resolve this upload my selected image?
Include in HtmlEditorExtender an event handler for the ImageUploadComplete event.
<ajaxToolkit:HtmlEditorExtender
OnImageUploadComplete="MyHtmlEditorExtender_ImageUploadComplete"
...
Within the ImageUploadComplete event handler, you need to do two things:
1) Save the uploaded image
2) Provide the URL to the saved image so the image can be displayed within the HtmlEditorExtender
protected void MyHtmlEditorExtender_ImageUploadComplete(
object sender, AjaxFileUploadEventArgs e)
{
// Generate file path
string filePath = "~/Images/" + e.FileName;
// Save uploaded file to the file system
var ajaxFileUpload = (AjaxFileUpload)sender;
ajaxFileUpload.SaveAs(MapPath(filePath));
// Update client with saved image path
e.PostedUrl = Page.ResolveUrl(filePath);
}
Make sure you checked
http://www.asp.net/AjaxLibrary/AjaxControlToolkitSampleSite/HTMLEditorExtender/HTMLEditorExtender.aspx and
http://stephenwalther.com/archive/2012/05/01/ajax-control-toolkit-may-2012-release
I am trying to programmatically set image of ImageButton.
My code is below:
String path="Images/1/";
path= path + string.Format("{0}", _ds.Tables[_bplp.SqlEntityX].DefaultView[0]["Photograph"]);
ImageButton1.ImageUrl = path;
I am saving images in my site folder Images/1 , and storing image name in database.
Problem lies when I am trying to display image in ImageButton.
Although after debugging it, path variable is taking correct path of image
as "Images/1/imagename.jpg", but still ImageButton doesnot show image.
Also, Images folder lies at root level of website.
try this
replace this
String path="Images/1/";
with
String path="~/Images/1/";
Also, you can try ResolveUrl();
ImageButton1.ImageUrl = ResolveUrl("~/" + path);
Problem was in my webconfig file, I had set incorrect site folder url in that, above code is working fine now
Thanks to all
my web page is uploading images to server folder which is 'd:\upresim'
I adding images with that code:
protected void Button2_Click(object sender, EventArgs e)
{
FileUpload1.SaveAs(Server.MapPath("~/image/a.png"));
Image1.ImageUrl = "~/image/a.png";
}
I have a selected image, that I receive from FileUpload that I have added from the selected image to server upresim into folder.
Afterwords I need to show the added image on Image1, but it show nothing what can I do?
You have to upload images under your web app folder, for that folder your app has to have rigths to write to filesystem, and then set relative url to Image control ImageUrl. You should also check if upload has a file, and preferably use file name from uploaded file.
For example, let's say that you have folder upresim in your web site root folder, then use this code :
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(Server.MapPath("/upresim/") + FileUpload1.FileName);
Image1.ImageUrl = "/upresim/" + FileUpload1.FileName;
}
I'm trying to display a local PDF file in a WebBrowser-Control. I didn't want to use the Adobe-Libraries, because they don't support 64-bit. Now I already have the code to display a PDF, but only if it is not on the local HDD. When I right-clicked on the WebBrowser-Control and displayed the SourceCode of the HTML, I saved it as an HTML-File to check, if the HTML-Code is correctly working. Well, it works.
My window only consists of a maximized WebControl. I think the problem are the Security Settings of the local Internet Explorer. I read that a custom IInternetSecurityManager could solve the problem, but I don't know how to implement it... :/
I'm using C# with .NET Framework 4.0
Here is my code:
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
string url = "C:/test.pdf";
string html = "<!-- saved from url=(0014)about:internet -->\n<html>\n<body>\n<embed src=\"" + url + "\" width=\"100%\" height=\"100%\"/>\n</body>\n</html>";
webBrowser.NavigateToString(html); // System.Windows.Controls.WebBrowser
}
I the "saved from URL" part does only work if I directly open the HTML-Code in IE, so please tell me what to do, to get this code work... Maybe you have a better solution for my problem. Thanks for your help!
Regards,
Chris
Just use
webBrowser.Navigate("file:///" + url);
I have image control.I want to load image from my specific path.
i have a code in page behind
string imagePath ="E:/DotNetProjects/Templates/Default/icons/Computer.png";
imgEditor.ImageUrl = imagePath;
imgEditor.AlternateText = "Unable To Find Image";
path is exist and image is also available but always load alternate text.
imgEditor is my image control ID.
Plz help to catch my mistake.Thanks.
Just put your image in solution(any folder or even in root) and path image uri from that (with src in asp page) like :
src="Templates/Default/icons/Computer.png"
The imagePath is a filesystem path... you need a URL... (something like http://...). The URL must be accessible from the browser i.e. you need to setup your webserver (IIS) to serve the respective path... I would recommend putting the image into the solution/project so that the URL is relative...