Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > check if image or file exists

Reply
Thread Tools

check if image or file exists

 
 
Filip De Backer
Guest
Posts: n/a
 
      06-22-2005
Hi everyone,

I want to check if a certain file or image exists.
The picture exists when I use th eurl in my IE, but in my C# code, the if
statement returns false.
Is there another way to do this?

string PictureUrl =
"http://www.lessius-ho.be/webapp/personeelsindex/images/543.jpg";
if (File.Exists(PictureUrl))
{
imgFotoPersoon.ImageUrl = PictureUrl;
imgFotoPersoon.Visible = true;
}
else
{
imgFotoPersoon.Visible = false;
}

thanks in advance,

Filip De Backer
 
Reply With Quote
 
 
 
 
Harolds
Guest
Posts: n/a
 
      06-22-2005
Not tested but you could try something like this:

Dim objResponse As Net.HttpWebResponse
Dim objRequest As Net.HttpWebRequest = Net.WebRequest.Create(URL)
objRequest.Method = "GET"
objResponse = objRequest.GetResponse()


"Filip De Backer" wrote:

> Hi everyone,
>
> I want to check if a certain file or image exists.
> The picture exists when I use th eurl in my IE, but in my C# code, the if
> statement returns false.
> Is there another way to do this?
>
> string PictureUrl =
> "http://www.lessius-ho.be/webapp/personeelsindex/images/543.jpg";
> if (File.Exists(PictureUrl))
> {
> imgFotoPersoon.ImageUrl = PictureUrl;
> imgFotoPersoon.Visible = true;
> }
> else
> {
> imgFotoPersoon.Visible = false;
> }
>
> thanks in advance,
>
> Filip De Backer

 
Reply With Quote
 
 
 
 
oraclevsmicrosoft
Guest
Posts: n/a
 
      06-23-2005
This sounds good, but if the URI is incorect this will throw an
exception. You should use a "try catch" structure to return a
boolean.
Here is a sample code close to your problem :
http://oraclevsmicrosoft.blogspot.co...sions-and.html
(look for the "loadUrl" method)

Hope this helps

Marc Boizeau

http://oraclevsmicrosoft.blogspot.com


"=?Utf-8?B?SGFyb2xkcw==?=" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Not tested but you could try something like this:
>
> Dim objResponse As Net.HttpWebResponse
> Dim objRequest As Net.HttpWebRequest = Net.WebRequest.Create(URL)
> objRequest.Method = "GET"
> objResponse = objRequest.GetResponse()
>
>
> "Filip De Backer" wrote:
>
> > Hi everyone,
> >
> > I want to check if a certain file or image exists.
> > The picture exists when I use th eurl in my IE, but in my C# code, the if
> > statement returns false.
> > Is there another way to do this?
> >
> > string PictureUrl =
> > "http://www.lessius-ho.be/webapp/personeelsindex/images/543.jpg";
> > if (File.Exists(PictureUrl))
> > {
> > imgFotoPersoon.ImageUrl = PictureUrl;
> > imgFotoPersoon.Visible = true;
> > }
> > else
> > {
> > imgFotoPersoon.Visible = false;
> > }
> >
> > thanks in advance,
> >
> > Filip De Backer

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check if a directory exists? folder.exists() does not work! Ulf Meinhardt Java 8 08-28-2009 12:26 PM
How to check if all *.jars in my CLASSPATH really exists? Automatic check (not manual) possible? Jason Stacy Java 2 04-27-2008 08:14 AM
finding if file exists or not in apache webdav server and if exists what is the mime type of it.... Totan Java 0 04-17-2006 05:13 AM
check if file exists on user machine Galina Grechka ASP .Net 4 01-13-2005 01:43 PM
Check if image file exists before linking to Image object Filip De Backer ASP .Net Web Controls 0 06-11-2004 07:24 AM



Advertisments