Relative File Locations

G

Guest

Hi, I'm using MS Visual Studio .NET 2003. In a PPC application I've bound the
contents of a list box to an XML file using the following code (and more)
supplied in a Sample Walkthrough:

xmlFile = Me.txtFile.Text
xsdFile = "\Program Files\Scorecard\FormatFile.xsd"

This works perfectly on my PPC and many others. However on an Italian PPC
the folder Program Files does not exist, instead the second line must read:

xsdFile = "\Programmi\Scorecard\FormatFile.xsd"

Obviously several other versions of Program Files exists in many other
languages. Is there any way to include a 'relative' file location based on
the location of the application?

Many thanks for your help.
 
F

Fabien

Hi,

with this line, you will have the path of the execution of your
application :
String path =
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName);

BR

Fabien Decret


ADENEO (ADESET)
http://www.adeneo.adetelgroup.com/


Ross a écrit :
 
G

Guest

Hi Fabien, thanks for the prompt response.

Unfortunately the 0 in the section GetModules()[0] is underlined as an
error, the error being: "Identifier expected".

Can you help me again. Thanks.

--
Regards,

Ross


Fabien said:
Hi,

with this line, you will have the path of the execution of your
application :
String path =
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName);

BR

Fabien Decret


ADENEO (ADESET)
http://www.adeneo.adetelgroup.com/


Ross a écrit :
 
W

Will Chapman

Ross said:
Hi Fabien, thanks for the prompt response.

Unfortunately the 0 in the section GetModules()[0] is underlined as an
error, the error being: "Identifier expected".

Can you help me again. Thanks.

Ross, I use this function:

private static string GetWorkingDirectory()
{
string cDir =

Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName);
return cDir;
}

Cheers...

Will Chapman
 
G

Guest

Hi Will, thanks for that.

I copied the code in as is, there were several errors, I think because of
the format, so I formatted the code into one continuous line. Having done so
there is just one error. The word string (in the text "private static
string") is underlined and the error is "Keyword is not valid as an
identifier".

Do I need to add an Imports.System.* line perhaps?

--
Regards,

Ross


Will Chapman" <"nbquidditch said:
Ross said:
Hi Fabien, thanks for the prompt response.

Unfortunately the 0 in the section GetModules()[0] is underlined as an
error, the error being: "Identifier expected".

Can you help me again. Thanks.

Ross, I use this function:

private static string GetWorkingDirectory()
{
string cDir =

Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName);
return cDir;
}

Cheers...

Will Chapman
 
W

Will Chapman

Ross said:
Hi Will, thanks for that.

I copied the code in as is, there were several errors, I think because of
the format, so I formatted the code into one continuous line. Having done so
there is just one error. The word string (in the text "private static
string") is underlined and the error is "Keyword is not valid as an
identifier".
I must admit a lot of VS error messages aren't exactly helpful. All
I can think of is to ask whether you have placed the code in a suitable
Class? Mine, for example is a method of my main form class, thus:
public FormSquare()
{
InitializeComponent();
InitializeCommonControls();
}

private static string GetWorkingDirectory()
{
string cDir = //etc

HTH

Will Chapman
 
G

Guest

I've tried to place the code in various locations with the same result...

Any other suggestions?
 
W

Will Chapman

Ross said:
I've tried to place the code in various locations with the same result...

Any other suggestions?
Apart from suggesting you try changing string to String I can't think
why it isn't working. It works perfectly on my VS 2005 setup and the
example is a direct cut & paste from my working code...??

PS I Often find it helps to search on MSN and Google for the actual
error string. If you are getting the problme the chances are someone
else is/has.

Good luck..


Will Chapman
 
G

Guest

Hi, I found a solution so I guess I should share it:

Public Function GetAppPath() As String

Return
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)

End Function
 
G

Guest

Should be GetCallingAssembly. If your implementation is in a class library
in the GAC you'll get back "\Windows" which is probably not what you want.

-Chris
 
G

Guest

Hi, is there a similar line that returns the Windows folder (if my
implementation is not in a class library in the GAC), which may be called
Windowi (I'm guessing!) on an Italian pocket PC. Also is there a similar
line that returns the My Documents folder, which may be called Mon Documento
(I'm guessing again!) on an Italian pocket PC?
 
P

Paul G. Tobey [eMVP]

SHGetSpecialFolderLocation(), which you would have to P/Invoke, will allow
you to get the localized names of those special folders. As usual,
OpenNETCF has this wrapped in the GetFolderPath() method of the
EnvironmentEx class in SDF...

Paul T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top