Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 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

22 Experts available now in Live!

Get 1:1 Help Now