简体   繁体   English

文件夹权限

[英]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 以下链接具有示例https://msdn.microsoft.com/zh-cn/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. 同样,作为输入参数的“ FileSecurity”类对象具有设置访问规则的功能,包括组级别控制。 Below link has example https://msdn.microsoft.com/en-us/library/system.security.accesscontrol.filesecurity(v=vs.110).aspx 下面的链接具有示例https://msdn.microsoft.com/zh-cn/library/system.security.accesscontrol.filesecurity(v=vs.110).aspx

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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