By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,528 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,528 IT Pros & Developers. It's quick & easy.

Open files as ReadOnly or Temp

P: 10
Hi All,
Now i currently open file from listbox using below code.
But i want to open as Read-Only or Temp file.
Because i don't want to allows user directly edit and save the file throught my program.
Please advice me....

Expand|Select|Wrap|Line Numbers
  1. Private Sub lsbFile_DoubleClick(ByVal sender As Object,
  2.  ByVal e As System.EventArgs) Handles lsbFile.DoubleClick
  3.         Dim sFileName As String
  4.         'Get the file to be opened from the listbox
  5.         sFileName = lsbFile.SelectedItem.DirectoryName & "\" & lsbFile.SelectedItem.name
  6.         Try
  7.             Dim myProcess As System.Diagnostics.Process = New System.Diagnostics.Process
  8.             myProcess.StartInfo.FileName = sFileName
  9.             myProcess.StartInfo.Arguments = vbReadOnly
  10.             myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal
  11.             myProcess.Start()
  12.  
  13.         Catch ex As Exception
  14.             MessageBox.Show(ex.ToString())
  15.         End Try
  16.     End Sub
  17.  
Regards,
Winzone
Aug 27 '10 #1
Share this Question
Share on Google+
1 Reply


Aimee Bailey
Expert 100+
P: 197
I tried this and it works fine, it basically just sets the file's attribute to readonly while notepad is open :)

Expand|Select|Wrap|Line Numbers
  1.         Dim sFileName As String = "D:\test.txt"
  2.         Dim f As New FileInfo(sFileName)
  3.  
  4.         f.IsReadOnly = True
  5.         f = Nothing
  6.  
  7.  
  8.         Dim myProcess As New System.Diagnostics.Process()
  9.  
  10.         myProcess.StartInfo.FileName = sFileName
  11.         myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal
  12.         myProcess.Start()
  13.         myProcess.WaitForExit()
  14.  
  15.         f = New FileInfo(sFileName)
  16.         f.IsReadOnly = True
  17.  
Aug 31 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.