Hello There,
i made a simple program to edit the notepad file...using C# ..but i get this error
when i try to run it in a user that has no administrative privileged...Code:System.UnauthorizedAccessException: Access to the path "C:\MyFolder\MySystem\MySystem.INI" is denied.
is there any way that it forcely edit the file?..i dnt know what method will be use...right now,i study impersonation but i don't know if this is the solution...
this my code...
Code:private void Form1_Load(object sender, System.EventArgs e) { try { ReplaceInFile(@"C:\MyFolder\MySystem\MySystem.INI","58.71.17.62","mlserver.company.com"); ReplaceInFile(@"C:\MyFolder\MySystem\MySystem.INI","192.168.12.100","mlserver.company.com"); ReplaceInFile(@"C:\MyFolder\MySystem\MySystem.INI","mlmysqlchatra","mlserver.company.com"); } catch (Exception ex) { throw ex; } }hope you can help me..thank youCode:static public void ReplaceInFile(string filePath,string searchText,string replaceText) { StreamReader reader = new StreamReader(filePath); string content = reader.ReadToEnd(); reader.Close(); content = Regex.Replace(content,searchText,replaceText); StreamWriter writer = new StreamWriter(filePath); writer.Write(content); writer.Close(); }


Reply With Quote

