473,324 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Open files as ReadOnly or Temp

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
1 3596
Aimee Bailey
197 Expert 100+
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

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

Similar topics

3
by: Gert Schumann | last post by:
I'm operating on sun OS 5.6 I ping a host every 10 seconds to get knowlegde wheather it is running or not. After about one and a half hour I get this Exception: java.io.IOException: Too many open...
10
by: Ian Rastall | last post by:
I've got a small search page at http://www.sundry.ws/search.html and I would like to add a section that allows me to open files on my computer, instead of having to go to File > Open. It's just...
0
by: markusp1982 | last post by:
Hello NG, I want to close open files which are locked by other users. I like to update an file. I dont want to delete the share file/folder. In the Computer Mangagement you can remove(cut) all...
20
by: Mark | last post by:
Is there a way in the dotnet to determine what files have locks and then what process is locking the file?
7
by: Lee | last post by:
Hey all, I'm using the following code to send stuff accross the network, appologies for it being in full, but I've really no idea exactly where this error is occuring. =======network...
6
by: massimo s. | last post by:
Hi, Python 2.4, Kubuntu 6.06. I'm no professional programmer (I am a ph.d. student in biophysics) but I have a fair knowledge of Python. I have a for loop that looks like the following : ...
4
by: jabslim via DotNetMonster.com | last post by:
excuse me, may i ask on how to open files only in drive "e:\" (which is my usb port for flash drives) using openfiledialog? because in the openfiledialog, even when i set my initialdirectory to...
6
by: AMD | last post by:
Hello, I need to split a very big file (10 gigabytes) into several thousand smaller files according to a hash algorithm, I do this one line at a time. The problem I have is that opening a file...
9
by: Bruno GUERPILLON | last post by:
Hi, I'd like, in a WIN32 environment, list all open files. Anyone got a clue how to do this ? Regards, Bruno.
13
by: jim | last post by:
Is there a way (using VB.Net or C#) to copy open or locked files? Thanks! jim
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.