C# block user to save directly an attachment in an shared drive

时间:2017-06-12 16:53:27

标签: c# .net

I'm working on an uploading function in an Application. The general function is user can upload a file and open it to read. when 'uploading', user upload the attachment to an shared NAS drive, when 'opening', user will open it from the shared drive. If user want to modify the attachment, they have to save it to their local and then modify it and then upload it again. So the key point is that we allow user to upload but not allowed them to modify directly on the shared path, and then I set the file attribute as read-only when they open it as below

    private void dvAttachment_CellClick(object sender, DataGridViewCellEventArgs e)
    {

            string filePath = System.Configuration.ConfigurationManager.AppSettings["sharedPath"].ToString() + "\\" + dvAttachment.SelectedRows[0].Cells["file_name"].Value.ToString();

            if (!System.IO.File.Exists(filePath))
            {
                string errMessage = "File is not existed any more";
                MessageBox.Show(errMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //ProcessStartInfo info = new ProcessStartInfo(filePath);

                System.IO.File.SetAttributes(filePath, System.IO.FileAttributes.ReadOnly);
                ProcessStartInfo info = new ProcessStartInfo(filePath);
                Process.Start(info);                                  
            }                

        }
    }

Now users can't save directly because the file they opened from the shared path is read-only, however they can still save as it on NAS drive with a different filename, which is not allowed by the application. I have no idea how to block user to do this way

Is there anybody can help to figure out how to make user not able to save their modification directly to the shared drive? Thanks very much!

0 个答案:

没有答案