Link to home
Start Free TrialLog in
Avatar of WCH_Applications
WCH_Applications

asked on

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

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.
ASKER CERTIFIED SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WCH_Applications
WCH_Applications

ASKER

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.
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.
The input didn't exactly solve my issue, but certainly improved my knowledge for future use. Thanks for the comments!