open file from root directory

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 89
Reputation: sfrider0 is an unknown quantity at this point 
Solved Threads: 0
sfrider0 sfrider0 is offline Offline
Junior Poster in Training

open file from root directory

 
0
  #1
Oct 21st, 2008
How do you open a file from the root directory without have to type the complete path like C:\folder\subfolder\file.txt? I have
  1. System.Diagnostics.Process.Start("file.txt");
It works fine when I type in the whole location but I need to send this file to another computer and it won't be in the same folder as it is now probably. I've tried moving the file around in the project folder and even put it in the debug folder with the .exe file.

I'm also using this same code to open a .exe file and I don't have to type in the whole path to get that, just file.exe. That works fine.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: open file from root directory

 
0
  #2
Oct 21st, 2008
If the above were an exe, you could rely on the computers path to pick it up if it were in say windows or system32 etc, such as notepad. However, you would need to know where the file was before you could start it. Either the computers current directory would have to be set to the directory in question, or you would need to put the full path in your start process command.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 89
Reputation: sfrider0 is an unknown quantity at this point 
Solved Threads: 0
sfrider0 sfrider0 is offline Offline
Junior Poster in Training

Re: open file from root directory

 
0
  #3
Oct 21st, 2008
is there a different command to use to just open a text file?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: open file from root directory

 
0
  #4
Oct 21st, 2008
Well, you could tell it specifically which app to open in, but as a general rule as long as the file extension is properly associated with an application eg, windows knows the equivelent of double click is to open it in something, it should trigger it.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,923
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 276
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: open file from root directory

 
0
  #5
Oct 21st, 2008
Perhaps you could use the "Path" type like so

Myfullpath = Path.GetFullPath(Myfile.txt)
This should return something like 'C:\MyFolder\MySubFolder\Myfile.txt' in Myfullpath.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: open file from root directory

 
0
  #6
Oct 21st, 2008
It would need to find "myfile.txt" to do that however.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,923
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 276
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: open file from root directory

 
0
  #7
Oct 21st, 2008
I assumed "myfile" was in the current working directory...
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: open file from root directory

 
0
  #8
Oct 21st, 2008
Along with all the previous, you MUST know where the file will be, whether that is remote or local. If it is remote you can use a unc path like \\192.168.1.100\shared\myfile.txt. A possibly better solution would be to use mapped network drives, and not necessarily hard code all these paths. If its on a remote machine you can access it like Z:\myfile.txt as long as Z is mapped to \\192.168.1.100\shared\
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC