| | |
open file in same folder as application
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2007
Posts: 164
Reputation:
Solved Threads: 1
can anyone tell me if it is possible in C# to open a file which is located in the same folder as the application without specifying the path to that file?
if both file and program is located for example on C:/containfileandprog can i open the file from within a program without writing C:/containfileandprog but just the filename.dat?
i have no control on where the file or the program is going to be installed so i cant specify them in advance. but i can make sure that they both end up in the same folder where ever the enduser might want to put them.
if both file and program is located for example on C:/containfileandprog can i open the file from within a program without writing C:/containfileandprog but just the filename.dat?
i have no control on where the file or the program is going to be installed so i cant specify them in advance. but i can make sure that they both end up in the same folder where ever the enduser might want to put them.
... what society overwhelmingly asks for is snake oil. Of course, the snake oil has the most impressive names —otherwise you would be selling nothing— like "Structured Analysis and Design", "Software Engineering", "Maturity Models", "IPSE", "MIS", "OO", "BPRE".... by Edsger W. Dijkstra
to open a file that's beside your application
Example to open text file called 1.txt which is beside your .exe
C# Syntax (Toggle Plain Text)
Application.StartupPath returns the path where your application starts from
C# Syntax (Toggle Plain Text)
System.Diagnostics.Process.Start(Application.StartupPath + "\\1.txt");
Last edited by Ramy Mahrous; Oct 23rd, 2007 at 9:43 am.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
if you are doing console, it should work like this:
C# Syntax (Toggle Plain Text)
string _sAppPathName = Process.GetCurrentProcess().MainModule.FileName; string _sDataFilePath = _sAppPath.Substring(0, _sAppPath.Length - (_sAppPath.Length - _sAppPath.LastIndexOf(@"\"))) + @"\yourfilename.yourextension";
Last edited by tostrinj; Oct 26th, 2007 at 11:00 pm. Reason: code bit looks like crap (formatting
===========================
can you repeat the part of the stuff where you said all about the things?
can you repeat the part of the stuff where you said all about the things?
![]() |
Similar Threads
- pls help how to open file in a application using jsp (JSP)
- Error Deleting File or Folder (Windows NT / 2000 / XP)
- Doubleclick to open file. (C#)
- Can seem to open my file (C++)
- IE, File Explorer and File Folder Short Cuts will not open (Viruses, Spyware and other Nasties)
- Open any file and List. (Visual Basic 4 / 5 / 6)
- Cannot open file : a (Windows 95 / 98 / Me)
Other Threads in the C# Forum
- Previous Thread: How to disable specific key code in keyDown event?
- Next Thread: call cmd processes and keeping them cmd window
Views: 8083 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagridview dataset datetime degrees development draganddrop drawing encryption enum excel file files form format forms ftp function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






