473,378 Members | 1,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

HELP File path confusion in WinForms app

Every example I see regarding opening a file uses paths like this:
FileStream inputStream = new FileStream ("C:\\file.txt",
FileMode.Open, FileAccess.Read);

Great if the file is always on the root of the C: drive but what if
that’s not the case?!

If I add a file to a project in my solution I can’t hard code the path
to the file which lives in something like C:\Documents and Settings
\Administrator\My Documents\Visual Studio 2005\Projects….

So how do I access a file using relative paths from the solution? And
if I have a program in one project trys to open a file in another
project how is this accomplished?

For example, I have two projects in my solution A & B. I have a
project reference in A to B. In B I have added an xml file to the
project. It’s in the root of the project. B has a class, BClass that
has a static function that needs to open that file. I call this
function in B from A, eg: BClass.OpenFile(). The file is physically
located in something like C:\Documents and Settings\Administrator\My
Documents\Visual Studio 2005\Projects (which will not exist on the
server this solution gets deployed to) and when A runs it’s the
currently executing program so any Application path will refer to A
not B but the file is in B. How to access that file?

TIA
G
Nov 1 '08 #1
4 2866
>On Nov 1, 5:29*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.comwrote:
Finally, for relatively small files one of the most reliable approaches is *
to just include the file as a binary resource in the output assembly (.exe *
or .dll). *Then it's not possible to deploy the assembly without the file, *
since it's actually part of the same file. *You would then retrieve the*
file as a byte stream or array from the resource itself.
Thanks for your reply. It's a small xml file so I'll look into using
binary resources. However, I'll be trying to access a binary resource
in one project exe from another executing project exe so not sure if
that will be a problem...

G

Nov 2 '08 #2
On Sun, 02 Nov 2008 08:43:44 -0700, GiJeet <gi****@yahoo.comwrote:
Thanks for your reply. It's a small xml file so I'll look into using
binary resources. However, I'll be trying to access a binary resource
in one project exe from another executing project exe so not sure if
that will be a problem...
I don't think there should be any difficulty at all. But, note that each
project only has convenient access to its own resources. You can load
resources from other assemblies, but it requires more explicit code. So,
if you need access to the data from a different assembly than where it's
stored, you might want to add a convenience method in the assembly where
it's stored to make accessing the data easier.

Note also that if the two projects are loaded in two different processes,
then obviously you'll have to go the explicit route of loading the
assembly and extracting the resource directly. It's not really clear from
your question what the scenario is, as you're distinguishing between "one
project exe from another executing project", which _might_ imply two
different processes. Or it might not. I can't tell.

Pete
Nov 2 '08 #3
>On Nov 2, 12:26*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.comwrote:
>*It's not really clear from *
your question what the scenario is, as you're distinguishing between "one*
project exe from another executing project", which _might_ imply two *
different processes. *Or it might not. *I can't tell.
I have two projects, one's an exe the other a dll. The dll is the one
that needs the xml file. The exe calls the dll so then the dll needs
to access the xml file. should be very common. Also, the exe project
has a reference set to the dll project so it can access it's methods
at design time.

My concern with an embedded resource file is, I believe every time you
change the xml file, since it’s embedded you need to recompile the dll
project and since the exe has a reference to the dll project, that
existing reference will no longer be valid and you need to remove and
re-add the reference. Just becomes a maintenance issue. Is this
correct?

G

Nov 3 '08 #4
On Mon, 03 Nov 2008 03:46:53 -0800, GiJeet <gi****@yahoo.comwrote:
[...]
My concern with an embedded resource file is, I believe every time you
change the xml file, since it’s embedded you need to recompile the dll
project and since the exe has a reference to the dll project, that
existing reference will no longer be valid and you need to remove and
re-add the reference. Just becomes a maintenance issue. Is this
correct?
Sort of, yes. You'd put the resource in the DLL, so only the DLL would
need recompiling. But yes, it would need to be recompiled if the file
changes, using that strategy.

Pete
Nov 3 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: DCK | last post by:
Hello I've path to file, which look like this: \\COMPUTER\D$\C++\FILE_TO_DELETE.JPG This path was generated by os.path.walk() function. When i try to delete this file, os.remove() can't find...
4
by: Active8 | last post by:
I did this once and can't remember how <blush> so I read the reportlab user guid. It says to unzip the reportlab archive - this is on w2k, BTW, with Python23 - to a directory and make a file...
23
by: da Vinci | last post by:
Greetings, Onwards with the school studying. Working on a program and need to delete a file from a known location on the hard drive but cannot get anything I do to work. I have tried to use...
3
by: Richard Steele (Basemap) | last post by:
Hi I am looking to develop an application that requires different graphics (skinned) and text (localisation) for each installation am currently using C# VS 2003 Would the way to go be Resource...
22
by: Jeff Louie | last post by:
Well I wonder if my old brain can handle threading. Dose this code look reasonable. Regards, Jeff using System; using System.Diagnostics; using System.IO; using System.Threading;
5
by: Seb | last post by:
Hi, I am trying to find the right regular expression which would only validate a URL with a given number of folders. Example: http://www.abc.com/folder/page.htm --Valid (4 slahes)
4
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the...
3
by: RP | last post by:
I have a text box in which I need the path of the file a user selects from the dialog box. I also want that the dialog box is filtered to show only image files, and when the user selects this file,...
0
by: raylopez99 | last post by:
I have a minor problem locating an image file to load as a Bitmap. A resource file "NudeSusan.jpeg" (which I think is actually a bmp file, originally taken from a jpeg of model Susan Spears) is...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.