473,657 Members | 2,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\Visua l 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\Admini strator\My
Documents\Visua l 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 2883
>On Nov 1, 5:29*pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.comw rote:
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.c omwrote:
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...@nn owslpianmk.comw rote:
>*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.c omwrote:
[...]
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
2971
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 it, os.path.fileexists() can't find it :( I can delete other files (i.e. \\COMPUTER\D$\C\FILE_TO_DELETE.JPG). I guess there's a problem with this C++ directory (++ exacly). I tried to change it to C\+\+, but this still not work. I've no idea how to...
4
5374
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 called reportlab.pth in the pythod dir. The only line in this file is supposed to be the path to the reportlib dir. Then I'm instructed to open the ... ok I'll close and reopen ... the python cmd line interpreter and type import reportlab
23
8935
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 the remove function that is included with <cstdio> but cannot get it to work properly. My reference book has the following....
3
361
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 Files, if so how do i deploy the installation driven resource file (does it sit in the application path) i can see a way of compiling the resource file into the application but that
22
4055
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
7606
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
6901
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 function creates the file as expected. When I loop through my array I get the error - "ArgumentException was unhandled - Illegal characters in path" The value "C:\Temp.txt" is the first value in the array - as it works
3
2904
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, the path of the file is shown on the text box.
0
2401
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 loaded onto the "Resources" tree of the Visual Studio Solutions Explorer, and correctly works. However, another file, "MyImageFile.png" (which is also a bmp file, sorry for the confusion, but originally was a png file), does not work. How can...
0
8395
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8310
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8826
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4155
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.