Relative Paths and Class Libraries

C#

    Next

  • 1. Memory Size
    If I have an IntPtr that points to some allocated memory, is there something that will tell me the size of the memory it points to? It seems like this info must be available somewhere since you do not need to pass a size value when freeing the memory. Thanks, Mike
  • 2. Good XML editors?
    I've been doing some home coding (using the free version of VS2005 - very sweet) and have run into a problem. The app uses a typical "deserialize XML" approach for configuration, and I've generated XSD for my configuration classes so that I can validate my config files. The problem is that, of course, hand-editing these config files is tedious, and since this is a hobby project I don't want to make a config gui. So currently I'm just doing the editing in Visual Studio, relying heavily on the XML intellisense... which is where the problem is. For some reason, the visual studio XML editor has trouble with my XSD. It gets confused by my XML frequently, and the autocomplete often fails to find certain members that are clearly mentioned in the XSD file. Ordinarilly I'd suspect the XSD or XML files except that a) they were generated by XSD.EXE and b) my XML deserializes just fine. so I'm left wondering why Visual Studio doesn't like my XML... and am starting to look into alternatives. I tried JAXE, quickly found it painful, and so am coming here for recommendations. Any good XSD-aware XML editors suitable for hobbywork?
  • 3. c# and mssql
    Hi, I am just wondering if anyone has any decent guides on working with sql server 2005 with c#? Thanks in advance.
  • 4. Write access to 'get'-only public property from within a class - best practice?
    Hi, I have a class with a get-only public bool property. This is good because I want users of this class to ONLY READ it. So I've defined it thus: private bool _IsDirty; public bool IsDirty{ get{ return _IsDirty; } } ... no problems there. But the methods from WITHIN this class needs to write to it, but the compiler will not allow me. So I guess I have 2 choices: 1. Put a set{ _IsDirty = value; } clause. This will allow the methods from WITHIN this class to write to it (i.e. IsDirty = true;), but it defeats the purpose because the users of this class are now ALSO able to modify it - THIS IS BAD!. 2. When writing to it, write to the private value (i.e. _IsDirty = true; ). This is my preferred choice at the moment, but it seems to defeat the purpose of encapsulation and good programming practice; because it the implementation of IsDirty is to be changed in the future, I'll have to step through all the code where I reference it. What is the preferred way, or is there another approach? have I missed something? Thanks, jack.

Relative Paths and Class Libraries

Postby lcota » Thu, 02 Jun 2005 23:55:29 GMT

I have a class library that makes use of a host of input files.  I'd
like to store the locations of these input files as relative paths as
opposed to hard-coded paths.  However, when I attempt to use a relative
path, the files never seem to be found.

The class library is wrapped by ManagedXLL and loaded with Excel as an
XLL file.  I am assuming that the default working directory will be the
directory from which the class library is loaded, so I have placed a
copy of the Datafile directory in this location, but this did not work.

Any ideas on what I may be doing wrong?  I am aware of the possibility
of using a config file, but I would like to avoid this route unless it
is absolutely necessary.

- Luis


Re: Relative Paths and Class Libraries

Postby Adam » Sat, 04 Jun 2005 07:52:07 GMT

Hey Luis,

I'm assuming that you are using C# seeing as how youe posting in a C# 
NG. Try this.

//Namespace  to use
using System;
//Store the star up path in a variable name StartUpPath
string StartUpPath = Application.StartupPath;

Application.StartUpPath gets the directory that the executable was 
launched from. It's the equivalent of VB 6s App.Path. If you are going 
to append a file name to it then you are going to want to do something 
line this.

string strFilePath = StartUpPath + @"\\filename.extensin";

I have used this in VS.NET 2003 and VS.NET 2005 so I sure it will work 
for you. just make sure your using the System namespace .... Like you 
wouldn't be lol

	- Adam


Re: Relative Paths and Class Libraries

Postby Adam » Sat, 04 Jun 2005 09:44:48 GMT

Just checked some sources and if the above code doesnt work use this

string StartUpPath = 
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);




Similar Threads:

1.How can I get relative path in Class Library?

I am trying to make some program with XML in class library by C#.
I read XML file in my program by using oXmlDoc.Load(xmlfilename);
But, It occured error... It read from C:\windows\system32,,, But my
XML file is in same directory with my program.
So, I know I have to use relative path.... 
Who knows how to get relative path in class library? 

Is there anyone who know this solution...

Please,,,Help me,,,,

I will appreciate....

2.absolute path to relative path conversion

3.relative path setting for include directory path

In places like 'Additional library directories' or 'include file path' for 
C++, I want to use relative path. But if I go to 'browse' button in project 
properties it sets me up with full path. I have to manually modify it into 
relative path. 

Is there a smart setting in IDE that will automatically insert a relative 
path I browse to ?

Thanks,
Raj

4.why relative hint path but absolute reference path

I have a vs.net 2002 solution that contains a number of projects
All projects are created in folders under the solution folder.
The idea here is that this entire solution should be 'moveable' ie. copied
to and useable from a new directory or computer.
And it almost is.

One project makes reference to an existing .net dll that also exists in a
folder under the solution folder.
The project file shows a relative hint path to the dll ie
"..\..\dllFolder\my.dll"
If I move the solution to a new folder and the open solution from the new
location, the dll can no longer be found.  if i restore the original
solution folder, the dll is once again found.  so obviously, although the
project file includes a relative hint path, vs.net is in fact looking for
the dll at an absolute location.  This is causing headaches as this solution
cannot be 'passed around'  without re-adding the reference to this dll.

is there some setting somewhere to get the relative path used ?
there does not seem to be any problem using relative project references - is
there some trick using a dummy project to get this to work ?

gerry



5.Get machine name path from relative or absolute path

Hello, is it possible in C#.Net to get a path to a file in the form
"\\Spain\Madrid\readme.txt" from a relative path i.e "readme.txt" or
from a absolute path in the following form "C:\Madrid\readme.txt" where
"Spain" is the name of the machine that the file is on? Thanks in
advance.

6. why relative hint path but absolute reference path

7. Project Output path converts to Relative path automatically

8. How to get absoulte path from relative path?



Return to C#

 

Who is online

Users browsing this forum: No registered users and 6 guest