By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,613 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,613 IT Pros & Developers. It's quick & easy.

Getting File Path

P: n/a
Hello Everyone and thanks for your help in advance. I am
working on an application that uses as helper class to
determine if an image file exists. If the file exists,
the path to the image is returned. Otherwise, a "Picture
not found" path is returned. I have that part workin
well. However, I have developed this on a local machine
and want to push the class to my prosuction server.
However, the paths change from machine to machine. I
want to be able to find the fully qualified path to a
particular file or directory. I tried File.GetFullPath
(myFilename), but that returns C:\WINDOWS\system32
\myFilename which is not where the file resides. I want
to make this as dynamic as possible. Any help would be
greatly appreciated. Thanks.
Jul 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
If you have a specific number of files, I'd seriously
consider adding them as embedded resources. To do this,
go to VS.nET and Add Existing ITem and point to the
file. This will add it in comiled form to your project.
Just make sure you set it's build property to Embedded
Resource. If you do this, it will always exist.

I'm not sure about the other part though. Why would it
exist on some machines and not others? Will it/SHould it
always exist locally or are you going to reference a
network share for instance. You can't hit a specific
device name with either FileInfo or Path classes, but I
think the path class may get what you want ..although if
you could show me a in depth example I'm sure we can
figure it out.

http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/cpref/html/frlrfsystemiopathclasstopic.asp

Let me know.

Bill
-----Original Message-----
Hello Everyone and thanks for your help in advance. I amworking on an application that uses as helper class to
determine if an image file exists. If the file exists,
the path to the image is returned. Otherwise, a "Picturenot found" path is returned. I have that part workin
well. However, I have developed this on a local machine
and want to push the class to my prosuction server.
However, the paths change from machine to machine. I
want to be able to find the fully qualified path to a
particular file or directory. I tried File.GetFullPath
(myFilename), but that returns C:\WINDOWS\system32
\myFilename which is not where the file resides. I want
to make this as dynamic as possible. Any help would be
greatly appreciated. Thanks.
.

Jul 19 '05 #2

P: n/a
The reason the paths will be different from machine to
machine is test machine (laptop) versus production
webserver. When I use the File.GetFullPath
(myFilename), it returns C:\WINDOWS\system32
\myFilename which is not where the file physically
exists. Why is this?
-----Original Message-----
If you have a specific number of files, I'd seriously
consider adding them as embedded resources. To do this,
go to VS.nET and Add Existing ITem and point to the
file. This will add it in comiled form to your project.Just make sure you set it's build property to Embedded
Resource. If you do this, it will always exist.

I'm not sure about the other part though. Why would it
exist on some machines and not others? Will it/SHould italways exist locally or are you going to reference a
network share for instance. You can't hit a specific
device name with either FileInfo or Path classes, but I
think the path class may get what you want ..although if
you could show me a in depth example I'm sure we can
figure it out.

http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/cpref/html/frlrfsystemiopathclasstopic.asp

Let me know.

Bill
-----Original Message-----
Hello Everyone and thanks for your help in advance. I

am
working on an application that uses as helper class to
determine if an image file exists. If the file exists,
the path to the image is returned. Otherwise,

a "Picture
not found" path is returned. I have that part workin
well. However, I have developed this on a local machine
and want to push the class to my prosuction server.
However, the paths change from machine to machine. I
want to be able to find the fully qualified path to a
particular file or directory. I tried File.GetFullPath
(myFilename), but that returns C:\WINDOWS\system32
\myFilename which is not where the file resides. I wantto make this as dynamic as possible. Any help would be
greatly appreciated. Thanks.
.

.

Jul 19 '05 #3

P: n/a
Hi Hugh,

You said:
|| I tried File.GetFullPath (myFilename), but that returns
|| "C:\WINDOWS\system32\myFilename" which is not where the file
resides

There isn't a File.GetFullPath(). But there is Path.GetFullPath() which
creates a path using the current directory. Which is not where the file
resides!

You need to obtain the FileInfo for "myFilename" and use
oFileInfo.FullPath().

Obtaining the FileInfo is left as an exercise.

Regards,
Fergus
Jul 19 '05 #4

P: n/a
>Hello Everyone and thanks for your help in advance. I am
working on an application that uses as helper class to
determine if an image file exists. If the file exists,
the path to the image is returned. Otherwise, a "Picture
not found" path is returned.


How about this:

public string GetImagePath(string aImageFileName)
{
if(File.Exists(aImageFileName)
{
return Path.GetDirectoryName(aImageFileName)
}
else
{
return "Picture not found"
}
}

The "Path" class is in the System.IO namespace.

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
Jul 19 '05 #5

P: n/a
If the file is supposed to be in the same directory as the application, then
you could do something like this.

string path = Assembly.GetExecutingAssembly().Location;
string fullName = Path.Combine(path,imageFile);
if ( File.Exists(fullName) )
{
}

"Hugh McLaughlin" <hu**@kmcnetwork.com> wrote in message
news:00****************************@phx.gbl...
Hello Everyone and thanks for your help in advance. I am
working on an application that uses as helper class to
determine if an image file exists. If the file exists,
the path to the image is returned. Otherwise, a "Picture
not found" path is returned. I have that part workin
well. However, I have developed this on a local machine
and want to push the class to my prosuction server.
However, the paths change from machine to machine. I
want to be able to find the fully qualified path to a
particular file or directory. I tried File.GetFullPath
(myFilename), but that returns C:\WINDOWS\system32
\myFilename which is not where the file resides. I want
to make this as dynamic as possible. Any help would be
greatly appreciated. Thanks.

Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.