473,537 Members | 2,796 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Image1.ImageUrl not rendering image when retrieving from different Directory

79 New Member
Hi,

I am working on a job portal. I have an Organization picture that I have to Save & Retrieve . My image saving code is working perfectly. But I am dumping the images in my D drive. Now when I use
Expand|Select|Wrap|Line Numbers
  1. Image1.ImageUrl = @"D:\DirecotyPath\Image.jpg";
  2.  
I does not render an image on the front end...
What can be done in this situation? And are there any alternatives to that?


Thanks,

Regards,

Syed Ahmed Hussain
Mar 30 '10 #1
10 15952
tlhintoq
3,525 Recognized Expert Specialist
Have you tried fixing the spelling of 'DirectoryPath'? Maybe you are just going to a folder that doen't exist?

Do you really have a folder named "DirectoryPath"? This sounds like a variable that should have been inserted into a string to make the full path.

Is it reasonable to assume that the viewer of the site doesn't have a D: drive with your photo?
Mar 30 '10 #2
Ahmedhussain
79 New Member
Have you tried fixing the spelling of 'DirectoryPath'? Maybe you are just going to a folder that doen't exist?
What I use here the word " Directory Path" is just a dummy name I am using here.

Do you really have a folder named "DirectoryPath"? This sounds like a variable that should have been inserted into a string to make the full path.

Is it reasonable to assume that the viewer of the site doesn't have a D: drive with your photo?
No it was just an example (Dummy) name to show that any kind of directory that I wish to open It opens easily and all the paths are stored properly in my database. I use the paths from my DB to retrieve the jpgs from that directory of the given drive ..

My aim is actually to save the jpgs anywhere on the disk (for right now, later there will be some changes according to the needs) and it simply will store the path in the Database and when you want to retrieve an image, it simply takes the path from the database and then use as the following code line and there are no issue's in the path I have debugged my program several times.

Expand|Select|Wrap|Line Numbers
  1. Image1.ImageUrl = imagepath;
  2.  
and in image path for example there is a path stored
@"D:\DirectoryPath\Gorilla.jpg"

Now at this point when it render the control, it will show the image control empty.


Regards,

Syed Ahmed Hussain
Mar 30 '10 #3
Frinavale
9,735 Recognized Expert Moderator Expert
The reason this isn't working is because the image is in a directory that the web server doesn't have access to. So if the image control tries to retrieve the image from the server it wont be able to.

There's a couple of solutions to this problem.
The first is to move the image into a temporary images folder that is on the web server (say in the website) so that the browser can download it.

The second is to implement an ASPX page that retrieves the image (as a stream) and writes it to the Response.OutputStream.

This ASPX page will not return HTML which is what is returned by default..and is expected by the web browser. You need to change the Response.ContentType to "image/jpg" to indicate to the browser that you are sending an image instead.

There is no asp code in this page...it's just pure server-side .NET code that retrieves the image (probably based on a parameter that is provided when the page is called) and writes that image to the stream.

For example, all that would be in your ASPX page would be the following to return the full size image (VB.NET code):
Expand|Select|Wrap|Line Numbers
  1.  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2.  
  3.    'Changing the page's content type to indicate the page is returning an image
  4.    Response.ContentType = "image/jpg"
  5.  
  6.    'Retrieving the name of the image 
  7.    Dim imageName = Request.QueryString("imgName")
  8.    Dim path = ""D:\DirectoryPath\"+imgName
  9.  
  10.    If String.IsNullOrEmpty(imageName) = False Then
  11.      'Retrieving the image
  12.      Dim fullSizeImg As System.Drawing.Image
  13.      fullSizeImg = System.Drawing.Image.FromFile(Server.MapPath(path))
  14.  
  15.      'Writing the image directly to the output stream
  16.      fullSizeImg.Save(Response.OutputStream, ImageFormat.Jpeg)
  17.  
  18.     'Cleaning up the image
  19.      fullSizeImg.Dispose()
  20.    End If
  21. End Sub
This code would be in a page called, say, GetImage.aspx ....

Now, when you specify the image source for the ImageControl you use "GetImage.aspx?imgName=Gorilla.jpg"

For example, in your page you would have:
Expand|Select|Wrap|Line Numbers
  1. <asp:Image ID="Image1" ImageUrl = "GetImage.aspx?imgName=Gorilla.jpg" />

-Frinny
Mar 30 '10 #4
tlhintoq
3,525 Recognized Expert Specialist
And I repeat
Is it reasonable to assume that the viewer of the site doesn't have a D: drive with your photo?
Meaning that me, sitting at my desk at my house looking at your site... I don't have 'your' D: drive with your D:\\DirectoryPath\Image.jpg on it - now do I?

Frinny you really do have much more patience than I do. It was terribly sweet of you to provide all the code to the OP
Mar 30 '10 #5
Frinavale
9,735 Recognized Expert Moderator Expert
No guarantees that it's going to work as is ;)

(but then again it looks right to me)
Mar 30 '10 #6
Ahmedhussain
79 New Member
@tlhintoq :

You needed patience for what ??? :D

After all you both are the moderators, someone gotta be more patient then I thought one should be :) ...

No you dont have D Drive, but again, I am saving it on my Server, right here on my laptop!!!!

I am not deploying my site right now....Moreover wont it be saving the images on the server???
Mar 31 '10 #7
Ahmedhussain
79 New Member
Server, means Client-Server Architecture???? I think you remember that???
Mar 31 '10 #8
Frinavale
9,735 Recognized Expert Moderator Expert
When I was referring to the web server I was referring to IIS....
You may consider your laptop as the server computer; but IIS doesn't have access to everything on the laptop.

It all depends on how you set up your website in IIS....but essentially when the browser requests some resource (a web page, an image, a JavaScript file...) the server has to return it. The only way that a browser can do this is using a URI. If the browser makes a request for "D:\somePath\something.xyz" then the server won't know how to translate it to retrieve the resource that you are looking for....never mind that you aren't even going to be able to make a request to the server using "D:\somePath\something.xyz"...the browser's just going to bock at this.

So you either need to copy/move/put the resource somewhere in your website so that you can create a URI/URL to the resource that the browser needs, or you need to create something (an ASPX page for example) that is accessible by the browser that will return the resource requested.

If the resource is on a different drive...you can't really specify a URL to that.

Therefore, I recommended that you create an ASPX page that retrieves the resources and writes it to the browser. This ASPX page is accessible by URL so that the browser can request the resource that is not "on the server" or "in the website".

-Frinny
Mar 31 '10 #9
Ahmedhussain
79 New Member
Frinny :

Thanks, I am learning so much from you guys :)

Regards,

Syed Ahmed Hussain
Mar 31 '10 #10
GolferGirly
1 New Member
I found a minor error in line 8:
Expand|Select|Wrap|Line Numbers
  1. Dim path = ""D:\DirectoryPath\"+imgName
where aspx image control property imgName should be the code behind variable imageName or some string literal.
Corrected:
Expand|Select|Wrap|Line Numbers
  1. Dim path = ""D:\DirectoryPath\"+imageName
Jul 26 '16 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

6
4546
by: Martin Bischoff | last post by:
Hi, I'm creating temporary directories in my web app (e.g. ~/data/temp/temp123) to allow users to upload files. When I later delete these directories (from the code behind), the application restarts and all active sessions are terminated. This error is also described in detail here:...
0
1458
by: Panic Student | last post by:
hi all, i'm having trouble with changing image when mouseover on a particular label. Below is what i attempted to but it didn't seem to work at all. I guess my concept is wrong ): Please enlighten me.... thanks a million~ Dim imgImage As WebControls.Image Dim lblLabel As Label
3
3639
by: Jakob Petersen | last post by:
Hi, I need to increase the speed when retrieving data from a hosted SQL Server into VBA. I'm using simple SELECT statements. How important is the speed of my Internet connection? (I have 4mbits) Should I index my tables or use Stored Procedures? Or is there a kind of "flush" function or readonly function or... Or is it simply a...
2
10301
by: blisspikle | last post by:
Is there any way to use the "imports" keyword for your current solution to use code (classes) that were used in a different solution in a different directory without compiling them to a dll? I would like to just link to the .vb files or the solution, and be able to use those classes in my current solution. I would like vb to compile all the...
3
3696
by: singhPrabhat | last post by:
I want to compile source files which is in different directory than Makefile. How can I do this? GCC=gcc DEFs=-DCUSTOMERCENTRAL_V11 -DUNIX -DLINUX -DOPENSSL -D_REENTRANT CCWebConfiguration.o: CCWebConfiguration.c $(GCC) -c -O2 $(DEFs) $*.c
9
25857
by: ghjk | last post by:
change the background image when Button Click ====================================== I' developing site with php and postgres. It has menus list in the left side. and all are images(jpg) EX:Add User, Edit User, Remove user(all arebuttons) I have another set of images with different color. Those will display only after the mouse click. How can...
1
1812
by: harry4you | last post by:
When retrieving the data from DB2 through Excel do we need to catalog the databases. I am currently using ODBC DSN less connection to connect.
3
2147
by: tess1243 | last post by:
I want the image to be changed when it is hovered, and display the changed image on the hovered image. I want the changed image exactly to display on the hovered image. Here is the code: HTML <div id="button1" class="alt" > <input type="image" name="GetStarted" class="alt-img10010" src="../Images/green.gif" style="border-width:0px;"...
0
7361
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7531
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7683
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5218
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3345
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3341
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
924
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
578
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.