Solved

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

Posted on 2011-09-06
5
254 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
  • 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now