views:

667

answers:

1

i have used the follwing function to write data to user application folder

private void WriteToLog(string source, string method, string msg)
{

 string LogFile =Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\test";            
 LogFile = LogFile + "\\Log.txt";
 StreamWriter sw = new StreamWriter(LogFile, true );
 string str = DateTime.Now.ToString() + "source=" + source + "\t Method=" + method + "\t" + msg;
sw.WriteLine(str);
sw.Flush();
sw.Close();

}

the above code working perfectly in administrator accounts, but failed in limited user accounts

+4  A: 

Limited users don't normally have write access to folders that are common to all users. Are you sure you don't mean to write to a different folder instead?

For example, you could use Environment.SpecialFolder.ApplicationData (current user, roaming data) or Environment.SpecialFolder.LocalApplicationData (current user, non-roaming data).

Christian Hayter
which folder i choose for limited user accounts
JKS
Conventionally, you would use ApplicationData for stuff that is user-specific but not necessarily limited to just that computer, and LocalApplicationData for stuff that is user-specific and also computer-specific (e.g. data that depends on the computer's installed software or installation paths).
Christian Hayter