Reputation: 34188
i know to create a file Using c# API. my requirement is bit different like i want to create a file which will lock by our system in such a way as a another 3rd part apps can read the file but the most important things is when 3rd part apps will read the file during this period no body can not move,copy & delete this file.looking for suggestion how to do it with c#. thanks
Upvotes: 0
Views: 128
Reputation: 3261
You can make service. Service will return new copy of base file for each requset. And 3rt part apps will get actual file at the time of the request.
Upvotes: 0
Reputation: 61382
Just open the file with FileShare.Read
:
using (var f = File.Open(filename,
FileMode.Open, FileAccess.Write, FileShare.Read)
This means exactly what you want: nobody else can now write to, rename or delete the file. They can still copy it, however, since if you can read the bytes, there's no way to prevent someone writing them somewhere else.
Upvotes: 2