By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,292 Members | 1,729 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,292 IT Pros & Developers. It's quick & easy.

File Permissions Issues

P: n/a
What .NET mechanism should I use to resolve permission issues before I
begin to copy directory structure/file(s) from one computer to another. I
have tried Try/Catch statement using DirectoryInfo and FileInfo but process
halts on error. The computers have Vista or XP Pro installed. Each computer
is attached to a Win 2003 or Win 2008 server.

Nov 11 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Good morning, Visine_Eyes.

Welcome to Microsoft Newsgroup Service. My name is Hongye Sun [MSFT] and it
is my pleasure to work with you on this issue.

This is a good question, however, it is hard to answer, because it depends
on different situations and different errors that you are facing. To better
answer this question, can you clarify the following questions for us about
the issue backgrounds?

1. What kind of application you are developing?

2. Are the computers to copy between in the same domain?

3. What is the permission error and its call stacks?

4. It would be better if sample code can be put here.

5. If there is something missing here, please feel free to let us know.

From my perspective, I have some suggestions to handle permissions in
general situations. They are just references for you before I fully
understand your situation.

1. Standard copy
In most cases, we do copy in following sequences:
a. Check if source folder / file exists.
If no, report to user.
b. Check if destination folder exists.
If no, create a new one.
c. Check if destination file exists.
If yes, override, skip or show dialog to let user decide.

We don't need to write code to check permissions before copying directories
and files. .NET Framework API already did that. For example:
FileInfo.CopyTo method will check for the read code access permission for
source destination and check for the write code access permission for
target destination before copying. If either of them is not valid, it will
throw "SecurityException" exception. It will also check the file permission
when copying, and "IOException" will be thrown.

As you mentioned, we can use Try/Catch to report errors to user and let
user to correct the permission errors manually.

Note: make sure that the account to run the application has the target
directory's write permission. Most errors are caused by this.

2. Impersonation
Sometimes that we have to copy files across domains, it requires the
current user to type another user name and password to impersonate
temporarily. It is commonly used in web application. To do that, we have to:
a. Get a token for a user
(http://alt.pluralsight.com/wiki/defa...HowToGetAToken
ForAUser.html)
b. Impersonate that user
(http://alt.pluralsight.com/wiki/defa...HowToImpersona
teAUserGivenHerToken.html)
Here is an example: http://www.codeproject.com/KB/cs/cpimpersonation1.aspx

Hope those references helps.

I will be waiting for your reply. Have a nice day.

Regards,
Hongye Sun (ho*****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 11 '08 #2

P: n/a
Hello Visine_Eyes,

I have not heard from you for several days since my last reply. I am
writing check the status of the issue. Would you mind letting us know any
progress from your side.

In my last reply, I was asking for background information about the issue.
That will help us to better answer your questions. In addition, I also
provided some comments on this issue for you to reference.

Please feel free to let us know if you have any problem. I will be more
than happy to help. Thanks.

Regards,
Hongye Sun (ho*****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 14 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.