Friends,
I have an xml file which is populated into my datagridview (DGV) with the following code:
DataSet ds = new DataSet();
ds.ReadXml(Form1.Paths.filename);
I wish to add Multiple user functionality in my winform, so that only 1 person is editing the xml file at a time. Others should get a notification to please wait.
I need ur suggestions for this please...

1 answers
You need to use the overload of DataSet.ReadXml which takes a stream rather than a file name if you want to control access to the underlying file by other users. Something like this for exclusive read access:
However, before you start altering all the file access code, you need to think carefully about what it is that you're trying to guard against.
For example, it's not usually a problem if multiple users can simultaneously read a file but it may be a problem if they can simultaneously write to it.
Will it be a problem if one user makes changes to the file and these are then immediately overwritten by another user who may not even know that the first user had already made some changes?
Do you actually need a common file or would it be better if each user had his/her own copy?
answered one year ago by:
17279
412
I helplessly need to have a common database (on the common network drive), so I need to control the write access on this file. Read access to all the users, whereas the write access should only be done after login.
17279
I think that DataSet.ReadXml (string) will give read access to other processes by default ( the usual situation in .NET). So you'll only need to use a FileStream explicitly to give the current user exclusive write access (specify FileShare.Read) when calling the DataSet.WriteXml method or whatever method you're using to update the file.
412
I'm writing my xml like this: ...........................................DataSet ds = (DataSet)dataGridView1.DataSource; if (ds != null) { DataSet copyDs = ds.Copy(); DataColumn dc = copyDs.Tables[cbtext].Columns["Date"]; copyDs.Tables[cbtext].Columns.Remove(dc); copyDs.WriteXml(Form1.Paths.filename); }
412
Maybe filestream is not the thing for me. I think I should inform the user before the user tries to login. otherwise filestream will not let the user write unless the file is relased from previous user. in a way.... the login & editing is wasted, better not to annoy the user on later stage. :)