473,322 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Create Image from relative path

I know that I can create an Image object by using a path like
C:\MyPictures\pic.jpg, but how can I create an Image object by using a path
like /MyPictures/pic.jpg where the path is relative to the site. For
instance, if the site is http://www.foobar.com, then /MyPictures/pic.jpg
would be fully qualified by http://www.foobar.com/MyPictures/pic.jpg.
Presumably there is a way to get the fully qualified path by giving the
relative path.
Nov 18 '05 #1
6 3013
MapPath()
--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"David W. Simmonds" <da***@simmonds.ca> wrote in message
news:X4WNb.127810$JQ1.117162@pd7tw1no...
I know that I can create an Image object by using a path like
C:\MyPictures\pic.jpg, but how can I create an Image object by using a path like /MyPictures/pic.jpg where the path is relative to the site. For
instance, if the site is http://www.foobar.com, then /MyPictures/pic.jpg
would be fully qualified by http://www.foobar.com/MyPictures/pic.jpg.
Presumably there is a way to get the fully qualified path by giving the
relative path.

Nov 18 '05 #2
Ok, great.

Now, to complicate the issue. What if the file exists on a completely
different web server than the asp.net code is executing on. The path to the
file would be the fully qualified path. How can an Image object be created
this way?

"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
MapPath()
--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"David W. Simmonds" <da***@simmonds.ca> wrote in message
news:X4WNb.127810$JQ1.117162@pd7tw1no...
I know that I can create an Image object by using a path like
C:\MyPictures\pic.jpg, but how can I create an Image object by using a

path
like /MyPictures/pic.jpg where the path is relative to the site. For
instance, if the site is http://www.foobar.com, then /MyPictures/pic.jpg
would be fully qualified by http://www.foobar.com/MyPictures/pic.jpg.
Presumably there is a way to get the fully qualified path by giving the
relative path.


Nov 18 '05 #3
Combine the System.Drawing.Image.FromStream() method with the
System.Net.WebClient class

Chad Mccune, MCSE, MCDBA

"David W. Simmonds" <da***@simmonds.ca> wrote in message
news:jnWNb.128026$JQ1.31594@pd7tw1no...
Ok, great.

Now, to complicate the issue. What if the file exists on a completely
different web server than the asp.net code is executing on. The path to the file would be the fully qualified path. How can an Image object be created
this way?

"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
MapPath()
--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"David W. Simmonds" <da***@simmonds.ca> wrote in message
news:X4WNb.127810$JQ1.117162@pd7tw1no...
I know that I can create an Image object by using a path like
C:\MyPictures\pic.jpg, but how can I create an Image object by using a

path
like /MyPictures/pic.jpg where the path is relative to the site. For
instance, if the site is http://www.foobar.com, then /MyPictures/pic.jpg would be fully qualified by http://www.foobar.com/MyPictures/pic.jpg.
Presumably there is a way to get the fully qualified path by giving the relative path.



Nov 18 '05 #4
I would use the OpenRead method of the WebClient class and pass it the url?

WebClient myWebClient = new WebClient();
Stream stream =
myWebClient.OpenRead("http://www.foobar.com/MyPictures/pic.jpg");
Image img = new Image;
img.ImageFromStream(stream);

I should also be able to pass in ftp://www.foobar.com/MyPictures/pic.jpg to
OpenRead?

"Chad McCune" <mccuneca@_NOSPAM_fpwk.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Combine the System.Drawing.Image.FromStream() method with the
System.Net.WebClient class

Chad Mccune, MCSE, MCDBA

"David W. Simmonds" <da***@simmonds.ca> wrote in message
news:jnWNb.128026$JQ1.31594@pd7tw1no...
Ok, great.

Now, to complicate the issue. What if the file exists on a completely
different web server than the asp.net code is executing on. The path to

the
file would be the fully qualified path. How can an Image object be created
this way?

"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
MapPath()
--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"David W. Simmonds" <da***@simmonds.ca> wrote in message
news:X4WNb.127810$JQ1.117162@pd7tw1no...
> I know that I can create an Image object by using a path like
> C:\MyPictures\pic.jpg, but how can I create an Image object by using a path
> like /MyPictures/pic.jpg where the path is relative to the site. For
> instance, if the site is http://www.foobar.com, then

/MyPictures/pic.jpg > would be fully qualified by http://www.foobar.com/MyPictures/pic.jpg. > Presumably there is a way to get the fully qualified path by giving the > relative path.
>
>



Nov 18 '05 #5
Duh. Stupid question. Use Image.ImageUrl.

"David W. Simmonds" <da***@simmonds.ca> wrote in message
news:Tm0Ob.134551$X%5.57848@pd7tw2no...
I would use the OpenRead method of the WebClient class and pass it the url?
WebClient myWebClient = new WebClient();
Stream stream =
myWebClient.OpenRead("http://www.foobar.com/MyPictures/pic.jpg");
Image img = new Image;
img.ImageFromStream(stream);

I should also be able to pass in ftp://www.foobar.com/MyPictures/pic.jpg to OpenRead?

"Chad McCune" <mccuneca@_NOSPAM_fpwk.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Combine the System.Drawing.Image.FromStream() method with the
System.Net.WebClient class

Chad Mccune, MCSE, MCDBA

"David W. Simmonds" <da***@simmonds.ca> wrote in message
news:jnWNb.128026$JQ1.31594@pd7tw1no...
Ok, great.

Now, to complicate the issue. What if the file exists on a completely
different web server than the asp.net code is executing on. The path to
the
file would be the fully qualified path. How can an Image object be created this way?

"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
> MapPath()
>
>
> --
> Curt Christianson
> Owner/Lead Developer, DF-Software
> www.Darkfalz.com
>
>
> "David W. Simmonds" <da***@simmonds.ca> wrote in message
> news:X4WNb.127810$JQ1.117162@pd7tw1no...
> > I know that I can create an Image object by using a path like
> > C:\MyPictures\pic.jpg, but how can I create an Image object by
using
a > path
> > like /MyPictures/pic.jpg where the path is relative to the site.
For > > instance, if the site is http://www.foobar.com, then

/MyPictures/pic.jpg
> > would be fully qualified by http://www.foobar.com/MyPictures/pic.jpg. > > Presumably there is a way to get the fully qualified path by

giving the
> > relative path.
> >
> >
>
>



Nov 18 '05 #6
Hi David,
Thank you for using MSDN Newsgroup! My name is Steven, and I'll be
assisting you on this issue.
From your description, your current question is how to create an Image from
a remote site via the Url address such as
"http://www.foobar.com/MyPictures/pic.jpg"
If there is anything I misunderstood, please feel free to let me know.

First , I'd like to confirm something on this issue:
Does the "create" you mentioned in your questoin means to create a Image
object(System.Drawing.Image) instance which contains the image stream of
the remote picture or just want to show a picture on a web page via its url
address?

If you just want to how a picture on a page via its Url address, then you
can use the "System.Web.UI.WebControls.Image" control or even just use the
"<img ..>" html element. As for the Image control, you can use its
"ImageUrl" property to specify a certain picture's Url address. Such as:
imgMS.ImageUrl =
"http://support.microsoft.com/library/images/support/bnr_microsoft.gif";

If you use the "<img >" html element, you can specify a picture like below:
<img
src="http://support.microsoft.com/library/images/support/bnr_microsoft.gif"
/>

Else case, if you want to retrieve a image stream from a remote site and
store into a "System.Drawing.Image"
class object. I think you need to consider Chad McCune's suggestion:
Using the WebClient class to get the remote file stream and store into a
Image object(System.Drawing.Image).
For example:
System.Net.WebClient wc = new System.Net.WebClient();
Stream sm =
wc.OpenRead("http://support.microsoft.com/library/images/support/bnr_microso
ft.gif");
System.Drawing.Image img = System.Drawing.Image.FromStream(sm);
img.Save(Server.MapPath("MS.gif"));
Please check out the preceding items to see whether they are helpful. If
you feel my suggestions not quite suitable for your situation, please feel
free to let me know more about your requirement so as for me to search for
further resource to assist you.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Erik Schulp | last post by:
Hi all, I am using a background image via a stylsheet. I've used this code: background-image:url("/images/tile.gif"); (which I think is correct) The image doesn't show up however, the path,...
11
by: KarimL | last post by:
Thanks for your advices... but i need to get the Image height because i dynamically resize the height of my webcontrol based on the image height. More i just have the url (relative parth) to the...
7
by: Nilesh | last post by:
I am using background-image attribute in a CSS file and linking the CSS file to aspx page. But strangly, background-image attribute is not working for relative URL. e.g. If I apply following css...
7
by: karthikeyan | last post by:
Hi, I am having some problems hosting my website. Everything works fine in my local machine but when I upload to propduction server, my images won't load properly. I have my state configuration...
2
by: rockdale | last post by:
I believe this must be a very sample question. I have a image dir under myWebsite (myWebSite is the root dir of my web appl) I have an ascx file under myWebsite/userControls in the c# of...
8
by: barb | last post by:
So that the world at large benefits from our efforts, here is one fully documented way to use Windows Irfanview freeware to create thumbnail web galleries (http://www.irfanview.com). STEP 1:...
2
by: Ruymán | last post by:
Hello!, is possible use relative path in access? for example use "photo\image1.jpg" instead of "c:\db\photo\image1.jpg", I try it but I cann't, but in Visual Basic if is possible. Other...
0
by: Arvi Laanemets | last post by:
Hi We are trying to create a simply ASP code, which creates guests list from Access database, and displays a country flag for every guest. All flag images are stored as *.gif in subfolder...
3
by: RN1 | last post by:
A user control has an image & a few Labels. When I view the ASPX page that uses this user control in my local machine, the image can be seen but when I upload the ASPX page & the ASCX page to my...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.