Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a file 1

Status
Not open for further replies.

Katy44

Technical User
Dec 12, 2003
723
GB
I need to physically open a text file from within a Windows app - I create it and write to it, and then I want to open it. Is this possible?
 
have a look at the StreamReader and StreamWriter classes in System.IO if you haven't found them already

Steve
 
I thought that the StreamReader class simply opened a file for the app to read itself. I want the app to make a call to open a file using whatever it is usually opened in and display it on the screen. I know that this is an operating system command - but it it possible from within a Windows Application?
If I'm completely wrong - sorry!
 
OK, I'm happy to open it in Excel, as it's a csv file. I have got as far as:

Code:
Excel._Workbook xlBook = xlApp.Workbooks.Open(logFile, Missing.Value, true, Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value, true);
which works fine (i've used it in other places to read in values from sheets) but I want to actually OPEN it! What does "Activate" do (from my app, it seems to do nothing!) If this was a website, I would use <A HREF=... how do I get the same effect in a Windows app?
 
This has been sorted - the above was fine, except I then needed an
Code:
xlApp.Visible = true;

All that pain!!

I would still like to know if there is a way to open a file without specifying how to open it - and let it be decided by the extension and the settings on the user's PC.
For example, some people have csv files opening in Notepad, some in Excel. Does anyone know how to do this, although there's no urgency at all?
 
If it depends on the extension of the file name, eg. "myExcel.xls" or "myText.txt" just write code to check the file name extension, "xls" or "txt" and do the correct process to open the file in either Excel or Notepad.

I'm not sure about the second situtation, what do you mean settings on the user's PC?? Here is what I think it means... You have a file called "myMovie.avi" and you change the PC settings so that you open all "avi" files in Real Player not (Windows Media Player, Crystal Player, etc..)

&quot; ahhh computers, how they made our lives much simpler ;) &quot;
 
The following code will open automatically the specified files without specifying the application:
Code:
private void button2_Click(object sender, System.EventArgs e)
{
   System.Diagnostics.Process.Start("C:\\myfile.xls");
   System.Diagnostics.Process.Start("C:\\todo.txt");
   System.Diagnostics.Process.Start("[URL unfurl="true"]http://www.yahoo.com");[/URL]
}
e.g. will open myfile.xls in Excel, todo.txt in notepad and Browser (default) on yahoo page.
-obislavu-
 
Thanks - that's exactly what I wanted. I'll try it out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top