public void CreateNewFile(string name) { string newPath = path + "\\" + name; try { File.Create(path + "\\" + name); //FileInfo finfo = new FileInfo(newPath); //FileSecurity fsecurity = finfo.GetAccessControl(); ////also tried it like this //fsecurity.ResetAccessRule(new FileSystemAccessRule(string.Format(@"{0}\{1}", Environment.UserDomainName.ToString(), Environment.UserDomainName.ToString()), FileSystemRights.FullControl, AccessControlType.Allow)); //fsecurity.SetOwner(WindowsIdentity.GetCurrent().User.AccountDomainSid); //finfo.SetAccessControl(fsecurity); //Console.WriteLine("OWWWWWWWWWWWNEEEEEEEEEEEER"+finfo.GetAccessControl().GetOwner(typeof(SecurityIdentifier)).Value); Program.proxy.LogSuccessfulEvent(user, "CreateNewFile"); DecideForSuccessful(Program.type); } catch (Exception e) { Program.proxy.LogErrorEvent(user, "CreateNewFile", e.Message.ToString()); WriteToEventLog.Instance().LogFailure(user, "CreateNewFile", "error"); throw new Exception(e.Message.ToString()); } }
public void DeleteFolder(string name) { try { Directory.Delete(path + "\\" + name); Program.proxy.LogSuccessfulEvent(user, "DeleteFolder"); DecideForSuccessful(Program.type); } catch (Exception e) { Program.proxy.LogErrorEvent(user, "DeleteFolder", e.Message.ToString()); WriteToEventLog.Instance().LogFailure(user, "DeleteFolder", "error"); throw new Exception(e.Message.ToString()); } }
public void DecideForSuccessful(LoggingType type) { if (Program.type.ToString() == "WriteToEventLog") { WriteToEventLog.Instance().LogSuccess(user, "CreateNewFile"); } else if (Program.type.ToString() == "WriteToXml") { WriteToXml(user, "CreateNewFile"); } else { Console.WriteLine("WrongChoice"); } }
public void DecideForUnSuccessful(LoggingType type, string method, string error) { if (Program.type.ToString() == "WriteToEventLog") { WriteToEventLog.Instance().LogFailure(user, method, "error"); } else if (Program.type.ToString() == "WriteToXml") { WriteToXml(user, method); } else { Console.WriteLine("WrongChoice"); } }
public void DeleteFile(string name) { string newPath = path + "\\" + name; try { if (Uri.IsWellFormedUriString(newPath, UriKind.Absolute)) { File.Delete(path + "\\" + name); DecideForSuccessful(Program.type); Program.proxy.LogSuccessfulEvent(user, "DeleteFile"); } else { throw new UriFormatException("Path not valid. The path " + "was not found or well formated"); } } catch (Exception e) { Program.proxy.LogErrorEvent(user, "DeleteFile", e.Message.ToString()); WriteToEventLog.Instance().LogFailure(user, "DeleteFile", "error"); throw new Exception(e.Message.ToString()); } }