Getting Permisions
-
Hi all. When i try accessing drive C: where the O.S.(windows 7), i keep on getting the error: Access to the path 'C:\Documents and Settings\' is denied. and throws the Exception: I have a good idea i have the following piece of code
private static void CopyFiles(string directoryPath, string destination)
{
try
{
int count = 0;
DirectoryInfo dir = new DirectoryInfo(directoryPath);
// DirectorySecurity dSecurity = dir.GetAccessControl();
// dSecurity.AddAccessRule(new FileSystemAccessRule(??);
FileInfo[] wordFiles = dir.GetFiles("*.doc*", SearchOption.AllDirectories);
foreach (FileInfo f in wordFiles)
{count++; f.CopyTo(destination + count.ToString() + f.Name); Console.WriteLine("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*"); Console.WriteLine("File name: {0} Copied", f.Name); Console.WriteLine("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\\n"); } } catch (UnauthorizedAccessException ex) { } }
I tried to request permisions in the two commented lines but i was totally unable. Please assist. :-(.
Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
-
Hi all. When i try accessing drive C: where the O.S.(windows 7), i keep on getting the error: Access to the path 'C:\Documents and Settings\' is denied. and throws the Exception: I have a good idea i have the following piece of code
private static void CopyFiles(string directoryPath, string destination)
{
try
{
int count = 0;
DirectoryInfo dir = new DirectoryInfo(directoryPath);
// DirectorySecurity dSecurity = dir.GetAccessControl();
// dSecurity.AddAccessRule(new FileSystemAccessRule(??);
FileInfo[] wordFiles = dir.GetFiles("*.doc*", SearchOption.AllDirectories);
foreach (FileInfo f in wordFiles)
{count++; f.CopyTo(destination + count.ToString() + f.Name); Console.WriteLine("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*"); Console.WriteLine("File name: {0} Copied", f.Name); Console.WriteLine("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\\n"); } } catch (UnauthorizedAccessException ex) { } }
I tried to request permisions in the two commented lines but i was totally unable. Please assist. :-(.
Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
Wamuti wrote:
Access to the path 'C:\Documents and Settings\' is denied. and throws the Exception:
yes it will throws Exception because Microsoft replaced
"Documents and Settings"
folder with"Users"
folder from Vista. hence same is the case in Windows 7 then if you want to access the "Documents and Settings" you should looking for Users folder use given Path instead of C:\Document and Setting in Windows 7 or even in VistaC:\Users
to get more clarification please read the thread of given link C:\Document and Setting[Win 7][^]
modified on Wednesday, January 5, 2011 6:00 AM
-
Hi all. When i try accessing drive C: where the O.S.(windows 7), i keep on getting the error: Access to the path 'C:\Documents and Settings\' is denied. and throws the Exception: I have a good idea i have the following piece of code
private static void CopyFiles(string directoryPath, string destination)
{
try
{
int count = 0;
DirectoryInfo dir = new DirectoryInfo(directoryPath);
// DirectorySecurity dSecurity = dir.GetAccessControl();
// dSecurity.AddAccessRule(new FileSystemAccessRule(??);
FileInfo[] wordFiles = dir.GetFiles("*.doc*", SearchOption.AllDirectories);
foreach (FileInfo f in wordFiles)
{count++; f.CopyTo(destination + count.ToString() + f.Name); Console.WriteLine("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*"); Console.WriteLine("File name: {0} Copied", f.Name); Console.WriteLine("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\\n"); } } catch (UnauthorizedAccessException ex) { } }
I tried to request permisions in the two commented lines but i was totally unable. Please assist. :-(.
Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
Hi, You should never have a hard coded folder name in your app.
C:\Documents and Settings\
might not exist for one of many reasons: - your system drive may not be called C: - your Windows system might be an international one using a different language - your Windows system might be more recent than XP and use a completely different folder name. The correct way is by usingEnvironment.GetFolderPath()
with the right parameter. That is bound to work on a range of Windows versions starting before XP. See the MSDN doc. :)Luc Pattyn [Forum Guidelines] [My Articles] [My CP bug tracking] Nil Volentibus Arduum
Season's Greetings to all CPians.
-
Hi, You should never have a hard coded folder name in your app.
C:\Documents and Settings\
might not exist for one of many reasons: - your system drive may not be called C: - your Windows system might be an international one using a different language - your Windows system might be more recent than XP and use a completely different folder name. The correct way is by usingEnvironment.GetFolderPath()
with the right parameter. That is bound to work on a range of Windows versions starting before XP. See the MSDN doc. :)Luc Pattyn [Forum Guidelines] [My Articles] [My CP bug tracking] Nil Volentibus Arduum
Season's Greetings to all CPians.
I understand. Supposing i wanted to write a file to a drive that is somewhat protected by the UAC, say Windows. This would throw an exception with an access denied message. I have a feeling i should request for permission, then the UAC would pop up, then if would say allow. Is that possible in code. That is really what i want to do. My English is not that good :-(
Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
-
I understand. Supposing i wanted to write a file to a drive that is somewhat protected by the UAC, say Windows. This would throw an exception with an access denied message. I have a feeling i should request for permission, then the UAC would pop up, then if would say allow. Is that possible in code. That is really what i want to do. My English is not that good :-(
Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
yes, since Vista, some folders (not drives) are protected. The idea is your app should not write there at all since these folders have special functionality for all users, not just for you. You can invoke the UAC dialog and get admin access rights if you must; see the relevant CodeProject articles[^]. :)
Luc Pattyn [Forum Guidelines] [My Articles] [My CP bug tracking] Nil Volentibus Arduum
Season's Greetings to all CPians.
-
yes, since Vista, some folders (not drives) are protected. The idea is your app should not write there at all since these folders have special functionality for all users, not just for you. You can invoke the UAC dialog and get admin access rights if you must; see the relevant CodeProject articles[^]. :)
Luc Pattyn [Forum Guidelines] [My Articles] [My CP bug tracking] Nil Volentibus Arduum
Season's Greetings to all CPians.
LPXYZ word cont3aining a digit
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
yes, since Vista, some folders (not drives) are protected. The idea is your app should not write there at all since these folders have special functionality for all users, not just for you. You can invoke the UAC dialog and get admin access rights if you must; see the relevant CodeProject articles[^]. :)
Luc Pattyn [Forum Guidelines] [My Articles] [My CP bug tracking] Nil Volentibus Arduum
Season's Greetings to all CPians.
LPXYZ word cont*aining an asterisk
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
yes, since Vista, some folders (not drives) are protected. The idea is your app should not write there at all since these folders have special functionality for all users, not just for you. You can invoke the UAC dialog and get admin access rights if you must; see the relevant CodeProject articles[^]. :)
Luc Pattyn [Forum Guidelines] [My Articles] [My CP bug tracking] Nil Volentibus Arduum
Season's Greetings to all CPians.
LPXYZ words containing a period for.each object.field object.method(parameter)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Thursday, January 13, 2011 3:46 PM
-
yes, since Vista, some folders (not drives) are protected. The idea is your app should not write there at all since these folders have special functionality for all users, not just for you. You can invoke the UAC dialog and get admin access rights if you must; see the relevant CodeProject articles[^]. :)
Luc Pattyn [Forum Guidelines] [My Articles] [My CP bug tracking] Nil Volentibus Arduum
Season's Greetings to all CPians.
LPXYZ double words containing a period for.each object.field object.method(parameter)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.