473,507 Members | 6,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting File Path

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
5 4657
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
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
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
>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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2518
by: Philip Ronan | last post by:
OK, here's my 2p worth: === Q. Why am I getting the error message 'Headers already sent'? A. PHP produces this error message when you try to set a header for a web page after you have already...
3
3633
by: Kali K E | last post by:
Hi, I could not understand how I can do the following things in Python. Please help me. 1. First I have to find the current directory from where the script is invoked. 2. Next I have to form a...
1
2922
by: orit | last post by:
I have the following xml file: <?xml version="1.0" encoding="utf-8" ?> <course id="2555" title="Developing Microsoft .NET Applications for Windows (Visual C# .NET)" length="5 days"...
7
2199
by: dixie | last post by:
I have been running some code from a form's on open event to run regedit if a registry key does not exist in the registry. It has been working fine, but I have had the path to the registry fix...
11
2006
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...
2
5263
by: Praveen | last post by:
Hi All, I have made a webservice in C# and it works fine in my machine. I ran into a crazy problem when I wanted to deploy it in windows 2003 server. I have run "aspnet_regiis.exe -i" to make...
0
3693
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
0
1225
by: sags | last post by:
Hi , Iam a new uesr of this group. I have a small doubt . Iam using the code mentioned below to retrive the data from tab delimited text file ., but Iam getting all the columns of the text file...
7
2071
by: Hitesh | last post by:
Hi, I have a small script here that goes to inside dir and sorts the file by create date. I can return the create date but I don't know how to find the name of that file... I need file that is...
18
3492
by: Aaron Gray | last post by:
Has anyone got a code snippet to separate out the path components, ie drive, path, filename, and extension ? Many thanks in advance, Aaron
0
7223
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,...
0
7110
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7372
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...
1
5041
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...
0
3191
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...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
411
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...

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.