简体   繁体   中英

Permissions on a folder

I have been looking for some time now and have not been able to find this. How can I set my program up to write or update a file from multiple users but only one group is allowed to open the read what is in the folder?

class Log_File
   {
    string LogFileDirectory = @"\\server\boiseit$\TechDocs\Headset Tracker\Weekly Charges\Log\Log Files";
    string PathToXMLFile = @"\\server\boiseit$\scripts\Mikes Projects\Headset-tracker\config\Config.xml";
    string AdditionToLogFile = @"\Who.Did.It_" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Year + ".txt";
    XML XMLFile = new XML();

public void ConfigCheck()
   {
       if (!File.Exists(PathToXMLFile))
       {
       XMLFile.writeToXML(PathToXMLFile, LogFileDirectory + AdditionToLogFile);
       }
    }
public void CreateLogFile()
    {

        if (Directory.GetFiles(LogFileDirectory).Count() == 0)
        {
            XMLFile.writeToXML(PathToXMLFile, LogFileDirectory + AdditionToLogFile);
            CreateFileOrAppend("");
        }
        else if (!File.Exists(XMLFile.readingXML(PathToXMLFile)))
        {
            XMLFile.writeToXML(PathToXMLFile, LogFileDirectory + AdditionToLogFile);
            CreateFileOrAppend("");
        }
        else
        {
            FileInfo dateOfLastLogFile = new FileInfo(XMLFile.readingXML(PathToXMLFile));
            DateTime dateOfCreation = dateOfLastLogFile.CreationTime;

            if (dateOfLastLogFile.CreationTime <= DateTime.Now.AddMonths(-1))
            {
                XMLFile.writeToXML(PathToXMLFile, LogFileDirectory + AdditionToLogFile);
                CreateFileOrAppend("");
            }
        }

    }

    public void CreateFileOrAppend(string whoDidIt)
    {
        using (IsolatedStorageFile storage = IsolatedStorageFile.GetStore((IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly | IsolatedStorageScope.User), null, null))
        {
            using (StreamWriter myWriter = new StreamWriter(XMLFile.readingXML(PathToXMLFile), true))

            {
                if (whoDidIt == "")
                {

                }
                else
                {
                    myWriter.WriteLine(whoDidIt);
                }
            }
         }

      }

This is my path where it needs to go. I have the special permission to open and write to the folder but my co workers do not. I am not allow to let them have this permission.

If I where to set up a database how would i change this code

LoggedFile.CreateFileOrAppend(Environment.UserName.ToUpper() + "-" + Environment.NewLine + "Replacement Headset To: " + AgentName + Environment.NewLine + "Old Headset Number: " + myDatabase.oldNumber + Environment.NewLine + "New Headset Number: " + HSNumber + Environment.NewLine + "Date: " + DateTime.Now.ToShortDateString() + Environment.NewLine);

I need it to pull current user, the agents name that is being affected the old headset and the new headset, and the time it took place.

While you create file, you have to set access rules to achieve your requirements. .

File.SetAccessControl(string,FileSecurity)

The below link has example https://msdn.microsoft.com/en-us/library/system.io.file.setaccesscontrol(v=vs.110).aspx

Also the "FileSecurity" class object, which is an input parameter, has functions to set access rules, including group level control. Below link has example https://msdn.microsoft.com/en-us/library/system.security.accesscontrol.filesecurity(v=vs.110).aspx

该问题将在一个新问题下打开,因为我将采用另一种方式记录所需的数据,谢谢大家的帮助

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM