Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Reading a text file using C# form application based on the location of the .application file

Posted on 2011-09-06
5
Medium Priority
?
262 Views
Last Modified: 2012-05-12
I am creating a windows form application with a browser object in it for our users to easily access an employee search web application we have. We recently updated the application from VB6 to VB.Net and the old shell it used does not quite fit the dimensions of the new version. The old shell was never documented and the source code can not be found, so I am creating a new one.

This form application will be accessed from a network share and should not be installed, so I am using the available online only option. This creates a .application file that executes the file without adding any shortcuts or add/remove programs files. However, the only way I've been able to make it read from the text file is by using an absolute file path. I want to use a relative file path and simply put the text file into the same folder as the .application file that is made when I publish the application. That way, if we move the application and the text file for any particular reason, the filepath does not need to change.

The current C# code to read:

StreamReader siteList = new StreamReader("\\\\ercfs01\\ERCPhone\\site.lst");
string urlString = siteList.ReadLine();
Uri url = new Uri(urlString);
browserPhone.Url = url;

Open in new window


I've tried different variations to try and make it read from site.lst located in whatever folder I place the published application into, but so far I have only had issues and I'm not finding any applicable information yet.

Any help is greatly appreciated.
0
Comment
Question by:WCH_Applications
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 28

Accepted Solution

by:
strickdd earned 250 total points
ID: 36490510
I'm not sure about this scenario, but most comonly this is how you would do it:

Application.ExecutablePath()

Given that you are executing from the network drive, I'm not sure if this will return the network path or the path of the .application file.
0
 
LVL 17

Assisted Solution

by:nepaluz
nepaluz earned 250 total points
ID: 36490516
In VB I'd use:
StreamReader siteList = new StreamReader(Path.Combine(My.Application.Info.DirectoryPath & "site.lst"))

Open in new window

The C# equivalent should be close
0
 

Author Comment

by:WCH_Applications
ID: 36490712
Using the exectuable path for a networked application does not work as we would intend. A file that does not install on the computer accessing it actually creates temporary files on the client computer in order to run locally.

For example, the filepath I received when using a combine was this:

C:\Documents and Settings\jmreddic\Local Settings\Apps\2.0\AZ4L26E5.A09\BEKGVLBZ.TMG\phon..tion_e91003f11de25671_0001.0000_4f2c4a8b94d03c77\site.lst

Your answers were definitely helpful in learning more about reading text files, but unfortunately this does not solve my current prediciment. I will continue to investigate. Thank you for the input.
0
 

Author Comment

by:WCH_Applications
ID: 36491661
Well, I was able to get in touch with another guy that works here and he made this so much simpler than I thought it was. He said to just point the reader to "site.lst" build the application, go into the release folder inside bin and copy the .exe to the network share. I tried that and now it works totally fine no matter where I move the .exe, as long as I move the text file as well.

Apparently I was apprpoaching this in an entirely more difficult manner. Again, thank you very much for the input, I really appreciate it.
0
 

Author Closing Comment

by:WCH_Applications
ID: 36491675
The input didn't exactly solve my issue, but certainly improved my knowledge for future use. Thanks for the comments!
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question