Solved

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

Posted on 2011-09-06
5
259 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 125 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 125 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

728 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