|
-
Aug 7th, 2007, 03:16 AM
#1
Thread Starter
Fanatic Member
Open a file as read only
Using the following :
System.Diagnostics.Process.Start("YourFile.txt");
I can open a file with whatever application is suitable for that file type if supported but what I want to know is.
Can i open that file in read only mode ?
I would prefer not to make a reference to the various COM objects for office applications.
Last edited by venerable bede; Aug 7th, 2007 at 06:50 AM.
-
Aug 7th, 2007, 03:34 AM
#2
Re: Open a file as read only
Where does Office come into this?
If you use System.IO class you can open a file for read/write operations using the ReadOnly file mode.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 7th, 2007, 04:53 AM
#3
Re: Open a file as read only
Open it yourself and lock it, then open it in the 3rd party application; or, if the application has a command-line switch to control read-only mode, start the application with that switch and pass the file name as an argument.
-
Aug 7th, 2007, 05:05 AM
#4
Thread Starter
Fanatic Member
Re: Open a file as read only
Cheers.
Is it possible to get a handle on the application closing ?
I don't think this is possible but it would be useful if I my application could be alerted when word,notepad or whatever closed so I could run some clean up code.
-
Aug 7th, 2007, 05:10 AM
#5
Re: Open a file as read only
Yes:
VB.NET Code:
Imports System.Diagnostics
' ...
Dim notepad As Process = Process.Start("notepad")
notepad.EnableRaisingEvents = True
AddHandler notepad.Exited, AddressOf notepad_Exited
' ...
Private Sub notepad_exited(sender As Object, e As EventArgs)
MessageBox.Show("Notepad was closed")
End Sub
-
Aug 7th, 2007, 05:40 AM
#6
Thread Starter
Fanatic Member
Re: Open a file as read only
Thanks penegate.
You are a god among men
-
Aug 7th, 2007, 05:42 AM
#7
Re: Open a file as read only
I like to think so, but it's nice to hear it from someone else.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|