locked
.Net apps sharing a file in a peer-to-peer network? RRS feed

  • Question

  • Can anyone tell me a bit about this?  I have a peer-to-peer network but the laptop is belly up at the moment and I am unable to do any experiments.

    If two apps try to share a file using StreamWriters will the latecomer be denied access?

    If a StreamWriter is accessing a file will other StreamReaders be allowed?

    How about if the file is on a Server instead of a peer?

    I vaguely recall a FileMode parameter which could be used to control file sharing but maybe I am thinking of the native Windows API.  Or maybe even another operating system.

    Thanks,  Bob

    • Moved by Mike Feng Tuesday, April 30, 2013 1:28 PM
    Monday, April 29, 2013 7:17 PM

Answers

All replies

  • Hi Ebob,

    Welcome to the MSDN Forum.

    Would you like to declare a file stream by this way: http://msdn.microsoft.com/en-us/library/y973b725.aspx 

    And set the 

    share
    Type: System.IO.FileShare

    FileShare value specifying the type of access other threads have to the file.

    To Write:http://msdn.microsoft.com/en-us/library/system.io.fileshare.aspx

    Allows subsequent opening of the file for writing. If this flag is not specified, any request to open the file for writing (by this process or another process) will fail until the file is closed. However, even if this flag is specified, additional permissions might still be needed to access the file.

    And here is a similar thread on this topic: http://stackoverflow.com/questions/11169354/multiple-filestreams-for-reading-writing-different-sections-of-same-file-concurr

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Reed KimbleMVP Tuesday, April 30, 2013 2:55 PM
    • Marked as answer by Mike Feng Sunday, May 12, 2013 8:50 AM
    Tuesday, April 30, 2013 1:27 PM
  • Thank you very much Mike.  That's most of what I was looking for.  But do you perhaps know if peer-to-peer networking supports the same file sharing capabilities as a Server?

    Thanks,  Bob

    Tuesday, April 30, 2013 4:56 PM
  • Hi Bob,

    I am afraid that you cannot use it in one server - multi client.

    In my above suggest, all the filestream plays as "client".

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, May 1, 2013 3:47 PM
  • Thanks Mike but I am not sure I understand.  If I have a server and have a file on the server then various clients can access the file using Read, Write, or ReadWrite.  Is that correct?

    But if I have a file which resides on a peer machine can other connected peer machines access the file using Read, Write, or ReadWrite?

    Thanks,  Bob

    Thursday, May 2, 2013 3:12 AM
  • Hi Ebob,

    >>If I have a server and have a file on the server then various clients can access the file using Read, Write, or ReadWrite.  Is that correct?

    Yes, when they have enough privileges.

    >>But if I have a file which resides on a peer machine can other connected peer machines access the file using Read, Write, or ReadWrite?

    It is the same when the other can access this file. 

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Saturday, May 4, 2013 12:12 PM