Show Images that has spaces in Image ASP.NET control - c#

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.

Related

In Jquery Img Tag in not populating image from DB because Src appending View path location in source that i cant remove ?? MVC

I have MVC application view page is under Home folder.
my image control is like,
<img id="user_img" height="100" width="90" style="border:solid" />
i am saving image in folder Img on the same level like App_data , App_Start etc.
i populating this img from response i am getting in Ajax.
$("#user_img").attr("src", response.EmpPic);
value i am getting from database is ~/Img/imageName.jpg
now according to jquery it set its source value but because my view is in Home folder it does not get image and show source i checked in browser developer tool is ,
"http://localhost:53798/Home/~/Img/imageName.jpg"
It will work if it should be like,
http://localhost:53798/Img/WelcomeScan124117716.jpg
I might change the source of image but how to edit above address it is getting due to view folder "/Home/"
Hopes for your suggestion thanks
Use it without the "~". You only need this in a few cases in Razor. It should work without it.
Try generating your path on the Controller side like this:
response.EmpPic=Path.Combine(Directory.GetCurrentDirectory(), #"/Img/", fileName)
This would give you the path of the current directory where the Img folder resides.

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();
}

asp.net image button's imageurl property not showing image of network location?

I am upoloading image to below location:
Location:\MyPC-pc\u165121142\MyFolder\pid\11\Profile\FImage\
But I cannot show the image from above location.
below is my control:
<asp:ImageButton ID="ImgImage" runat="server" />
I am checking using below method for file exists or not(it works) but when I set image file location to ImageUrl property, I can not see image in browser.
if(System.IO.File.Exists("\\MyPC-pc\u165121142\MyFolder\pid\11\Profile\FImage\Koala6192013104451AM.jpg"))
{
ImgImage.ImageUrl="\\MyPC-pc\u165121142\MyFolder\pid\11\Profile\FImage\Koala6192013104451AM.jpg";
}
note: This folder (u165121142) is in network. I have given it full rights
The user's browser needs to be able to retrieve from the URL. It's retrieved at display time.
You could either put the file on a web server and use an http url, or you might be able to use a file: url. Either way, the browser won't retrieve from a disk file directly.
Is that your actual code? 'Cause you probably need to use double backslash, like:
if(System.IO.File.Exists("\\\\MyPC-pc\\u165121142\\MyFolder\\pid\\11\\Profile\\FImage\\Koala6192013104451AM.jpg"))
{
ImgImage.ImageUrl="\\\\MyPC-pc\\u165121142\\MyFolder\\pid\\11\\Profile\\FImage\\Koala6192013104451AM.jpg";
}

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

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());

Unable to load image in img control in asp.net

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...

Categories

Resources