I draw diagrams, but I see old image on the new page - c#

I am developing a C# web project. I run it on the local web server.
I draw. I show image as follows:
bitmap.Save(Server.MapPath("diagram.jpg"), ImageFormat.Jpeg);
Image1.ImageUrl = ResolveUrl("diagram.jpg");
I don't see new image. Only old one, which I had after changing image name
(Say, I change diagram.jpg to diagram2.jpg).
Browser is Firefox.
The design page in C# is simple. Just Image and few TextBoxes on the page.
No UpdatePanel and such.
Something with caching... But how to fight with that...

But how to fight with that.
Always use a separate path / name. Pug a GUID somewhere. Simple like that. Different file can not be cached.

I'm not sure what ResolveUrl does, but try adding a querystring to the image url so that the page always gets a "fresh" file. Something like this:
Image1.ImageUrl = ResolveUrl(string.Format("diagram.jpg?v={0}", Guid.NewGuid()));

You can alternative write the image file as
diagram.jpg?ver=2
to keep the same image file, but force the browser to update it.

If Image has Same name and URL browser picks the image from the cache and displays the same for faster loading of the pages.
Even if you change the image server side the same cached image is displayed until you clear the cache of the browser. You can use query string to change image url like below.
Image1.ImageUrl = ResolveUrl("diagram.jpg?" + DateTime.Now.Ticks.ToString());

Related

image updated on page works fine only after clearing the browser history in asp.net

I have a page named sample.aspx.
This page reads image from user.and saved details shows to the user using a table....When the user click on the edit button it shows all the details back to the fields(including image).Update works fine for me.But The page shows the updated image only after clearing history of browser.How to solve this?pls help me
Thanks and regards
Nijisha k C
If you don't want the image to be cached you can attach a random query string (server time might be a good idea) to the image. This will make sure the browser always checks for updates:
<img src="picture.jpg?123415215125">
This is likely due to the Browser Cache than anything to do with .NET. If the image SRC is the same when revisiting a webpage before the cache expired date the browser will just grab the image from the local browser cache rather than the server
That said its common practice in this case is to update a parameter on the Image SRC usually by assigning a timestamp.
Use something like this:
newImage.src = "image.jpg?parameter=" + new Date();
To produce:
<img src="image.jpg?parameter=1436422632">

Show Images that has spaces in Image ASP.NET control

I am setting an absolute path to Image control. This path is having spaces. After assigning the path to ImageURL property of the Image ASP.NET control, it does not show the image. I don't have option to remove the spaces as it is the requirement. Also, this path is outside the root directory(There is basically a FileUpload control that takes the file and then I am assigning the path to Image control).
Firstly is it possible to do. If yes how? Below are the code blocks relevant to the question
Server Code
target.ImageUrl = strImagePath;
where target is the Image control id
File Path: C:\Users\WebMaster\Downloads\2 States Full Vedio Songs 720p Bluray Encodded By(Khanz)\Screenshoot\vlcsnap-2014-05-17-13h22m13s103.png
Rendered HTML
<img id="target" alt="[Jcrop Example]" src="C:\Users\WebMaster\Downloads\2%20States%20Full%20Vedio%20Songs%20720p%20Bluray%20Encodded%20By(Khanz)\Screenshoot\vlcsnap-2014-05-17-13h22m13s103.png" />
Thanks in advance for your help.
Thanks Manson. I was so wrong. The image has to be hosted on the web server to access. Actually, this is what I want to cut down. Uploading the image from local user path to server folder was taking time. But I forgot the basics. Re-writing your comment as answer.

how to map image to image button in asp.net with session using c#?

I have an image folder in my project solution. I capture the image for a customer and i keep it in it. After i fill the details I redirect to another aspx page and i take the pic and come back to registration page and map the image to an image button i am using session variable to map the image path which is in the image folder. My problem is I get the same image even if i take a new pic. I am keeping jus one pic at a time in the image folder why do i get the previous image which is not in the image folder. Am i not supposed to get the new pic which i have taken? Please elaborate more on this and provide me a solution..I would be grateful to you..
There could be browser caching at play. One way to get around it is to add a random querystring param to the image url (a timestamp etc) to make the image url unique.
<img src="someImage.png?someParam=1234" />
You cannot delete browsers cache programmatically however below code will help you for disabling caching and clears existing cache from your application... Caching is your problem as you explained in question.
public static void DisablePageCaching()
{
//Used for disabling page caching
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();
}

How to navigate to an image from within c#

I was wondering how you, on WP8, can navigate to / open an image?
Suppose I just saved an image to my Save Pictures folder, I now want to navigate the user to that image so they can share it on facebook.
Lets say I have:
MediaLibrary lib = new MediaLibary();
Picture p = library.SavePicture("foo.jpg", imgStream);
How can I navigate to p as if the user had clicked it from the picture library?
A simple method for navigate into image is related to Efficient image manipulation in C#. I think that you need an framework for precessing like AForge.NET.
You could always try passing the url of the image as a string to a page that has nothing on it except an "Image". Then as soon as you navigate to the page you open up the image from the url(url can be for an isolatedstorage file) and set it as the "Image" on the page.

Displaying image that was previously uploaded to server

For a project I'm working I would like the user (admin) to be able to change the picture on the page he is currently on. I managed to upload the image to "the server" using interlink. This basicly uploads it to a given folder on a server, in my case being: Interlink/Uploads.
But now I don't really know how can I tell my website to replace the source of the image that is currently shown with the source of the uploaded image.
Another something I would like to do is create a simple image gallery with all the images in that folder, once again I don't know how to do this.
I hope somebody can help me, Thanks.
Thomas
Edit: Just so clarify, the application is written in silverlight (XAML, C#). I apologise for any inconvenience.
I take it that the "Silverlight" portion of this question is related only to Interlink (your file uploader), and not to the page itself, which I presume is straight HTML.
If that's the case, you've got several options for changing the local image. The simplest way is simply to wait until you know that your file upload has finished (presumably Interlink has some way of notifying you that this is the case), and then run something like this bit of JavaScript:
<script type='text/javascript'>
function changeImage(newImageSource) {
document.getElementById('myTargetImage').setAttribute('src', newImageSource);
}
</script>
As far as displaying a simple image gallery with all the images in the folder, my recommendation would be to look into one of the numerous jquery plugins that handle this sort of thing, e.g.:
http://www.1stwebdesigner.com/css/fresh-jquery-image-gallery-display-solutions/
EDIT: Silverlight Options
You basically have the same options, except you're doing them in C# instead of JavaScript. For instance, when Interlink tells you that the new image has been uploaded, run this:
string imageName = "something.jpeg";
var ub = new UriBuilder(HtmlPage.Document.DocumentUri);
ub.Path = "/Interlink/Uploads/" + imageName;
img.Source = new BitmapImage(ub.Uri);
And for an image carousel, something like this:
http://3dimagecarousel.codeplex.com/
You'll just need to provide the URL's of all the images. The easiest way to do that is probably to expose a web service method that lists them all.

Categories

Resources