locked
Open file as read only RRS feed

Answers

  • You could first open the file with File.Open method so it is used by another process before using ProcessStartInfo.

    Chris

    Code Samples: Code Samples

    • Proposed as answer by chriga Monday, May 13, 2013 6:39 PM
    • Marked as answer by Bob Shen Friday, May 31, 2013 10:10 AM
    Friday, May 10, 2013 7:09 PM
  • There are two totally different thigns here:

    1. Open a File read only.

    2. Start a Process

    The two have nothing and absolutely nothing to do with one another!

    To 1::

    http://peterkellner.net/2009/12/07/csharp-streamreader-readonly/

    Another solution is this, wich may allow you to even open Files for reading if they are already opened R/W by soem other process:

    http://stackoverflow.com/questions/897796/how-do-i-open-an-already-opened-file-with-a-net-streamreader

    To 2: I have no idea how do you think ProcessStartInfo comes into this.

    You should go one step back and tell us what problem you think this will solve. Because you are very likely on the totally wrong track.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2

    • Marked as answer by Bob Shen Friday, May 31, 2013 10:10 AM
    Saturday, May 11, 2013 4:07 AM

All replies

  • One way is you can create a program to open File in readonly mode

    and start program.exe using ProcessStartInfo

    Regards

    MG

    Thursday, May 9, 2013 10:25 AM
  • var attributes = File.GetAttributes(path);
    
    File.SetAttributes(filePath, attributes | FileAttributes.ReadOnly);
    
    System.IO.Diagnostics.Process.Start(fileName);
    
    File.SetAttributes(filePath, attributes);

    As Kushwaha

    • Proposed as answer by chriga Monday, May 13, 2013 6:39 PM
    Thursday, May 9, 2013 10:26 AM
  • Currently I am using the same code but its actually modifying the Actual File's Read Only attribute which is what we don't want.

    http://www.techknackblogs.com



    Friday, May 10, 2013 4:26 PM
  • Can you pls elaborate? I am unable to understand you.

    www.techknackblogs.com


    techknackblogs

    Friday, May 10, 2013 4:27 PM
  • Why do you need to use ProcessStartInfo? What do you intend to do with the file?
    Friday, May 10, 2013 4:40 PM
  • You could first open the file with File.Open method so it is used by another process before using ProcessStartInfo.

    Chris

    Code Samples: Code Samples

    • Proposed as answer by chriga Monday, May 13, 2013 6:39 PM
    • Marked as answer by Bob Shen Friday, May 31, 2013 10:10 AM
    Friday, May 10, 2013 7:09 PM
  • There are two totally different thigns here:

    1. Open a File read only.

    2. Start a Process

    The two have nothing and absolutely nothing to do with one another!

    To 1::

    http://peterkellner.net/2009/12/07/csharp-streamreader-readonly/

    Another solution is this, wich may allow you to even open Files for reading if they are already opened R/W by soem other process:

    http://stackoverflow.com/questions/897796/how-do-i-open-an-already-opened-file-with-a-net-streamreader

    To 2: I have no idea how do you think ProcessStartInfo comes into this.

    You should go one step back and tell us what problem you think this will solve. Because you are very likely on the totally wrong track.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2

    • Marked as answer by Bob Shen Friday, May 31, 2013 10:10 AM
    Saturday, May 11, 2013 4:07 AM