473,385 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Rename via Directory.Move gives Access Denied Error

I get this error intermittently in error reports submitted from users. Can't reproduce it myself. Most seem to be running XP so it's not a Vista issue.

My C# code creates a temporary folder then copies files to it. At the end it removes the Temp from the name and replaces it with a date stamped name:

backupPath = destFolder + "\\Backup_" + String.Format("{0:yyyyMMdd_HHmmss}", DateTime.Now);

Directory.Move(destFolder + "\\Temp_Backup",backupPath);

The Move operation throws an exception: Access to the path xxx is denied.
where xxx is the temp folder path (i.e. destFolder+"\\Temp_Backup);

Note that this is the folder into which I had just successfully copied one or more files. Note also that I'm not moving the folder but just renaming it.
Feb 5 '10 #1
2 6534
tlhintoq
3,525 Expert 2GB
If it is over a network at the client's yet local PC at your testing that might explain it. Sometimes you need to give time to servers to complete the task. They will lie to client PC's and tell you a copy is complete when it really isn't.

I try to simulate poor client networks at home by using two slow WiFi connected computers as server and client.

I would suggest that you keep trying to do the rename for 15 seconds, then bail out of the retry loop either when the time is up, or when you have done it successfully.

I can make some general suggestions that apply to good coding practice.
  • Assume that everything is broken, or at least not ideal.
  • Presume that the user is going to provide data in a format or manner that you just didn't expect. If you use a textbox for a number, the user will type "One".
  • Assume that hardware breaks in the middle of what you are doing, so you have to recover.
  • Take a few extra lines of code to get standards like the boot drive, the number thousands seperator etc. Don't assume that you have a C: drive or that a comma is the separator because not everyone is in America.
  • Check that files/folders exist, even if you just did a call to make it: You may not have permissions.
  • Don't assume the harddrive has room for what you are doing: They do fill up. Usually right in the middle of you writing to your log file.
  • Get used to placing breakpoints and walking through the code line by line. Double check EVERYTHING on every line. Keep the "Locals" and "Autos" windows open so you can see your values.
    • Put a breakpoint on the first line of the method causing trouble.
    • When the code stops there, walk through line by line with F-10.
    • Check the values of your assumptions (looking at the Locals and Automatic variable windows as well as hovering the mouse over the variables in the code (hothelp will popup).
  • Stop. Breath. Relax. Then reason out the problem. Cut it down by sections or halves. "The value was good here, then at this method it wasn't. Where did it go between 'A' and 'B'?"
  • Range check and validate values. Confirm that you didn't get a zero when you are only set to accept 1-10. Confirm your objects and values aren't null. Initialize them to a known default if possible. If a selection can be from 0-10, then initialize to -1: Now you have something to check for.
Feb 5 '10 #2
The folder itself is on the user's local drive. The files I'm copying into it do not come from a network drive but they come from a fairly slow USB flash drive. Perhaps this is part of the problem although, as I said, the folder I am trying to rename is local.
Feb 6 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bob Bedford | last post by:
I've tried everything seen on Internet, but nothing works: I'm trying to move a file from a dir to a subdir (WinXP Pro, Apache, PHP 4.3.3) Here is the code: chmod($XMLPath, 0777);...
3
by: Scott Whitney | last post by:
oldName=/backup/backups/data/WWW_httpd.conf_backups/20050204.httpd.conf newName=/backup_old/data/WWW_httpd.conf_backups/20050204.httpd.conf os.rename(oldName,newName) gives: OSError: ...
7
by: Tom | last post by:
I'm having a problem using a path with spaces as a parameter to os.rename() in a program on WinXP. This works fine at the command line (where the folder "c:\aa bb" exists) > os.rename( "c\aa...
0
by: Jeff Reed | last post by:
I am experiencing the the problem outlined the below. Unfortunately, I am using WinXP and I not sure if I can apply the solution due to lack of security control Any feed back would be apreciated ...
7
by: Jaydeep | last post by:
Hi, Anybody knows how to create virtual directory programmatically under root directory ofcourse from code-behind. I am developing web-based application where I need to create a folder and making...
1
by: Liming | last post by:
Hi, I'm trying to move a directory into another using Directory.Move(src,dest); but I keep getting this System.IO Exception access to directory is denied I have ASPNET (full control) to the...
5
by: Max | last post by:
hi i have file browser control to select any file and a button to upload file on my web page now when i select any file. now on click of upload button i have check that file exist or no if...
3
by: gsoguerrilla | last post by:
Hi, I have limited knowledge in php and I am having trouble with uploading an image to a remote directory and resizing it if it's larger and renaming it to a unique id, while at the same time I...
3
by: rn5a | last post by:
An inquisitive question...... A ListBox lists all the directories & files residing in a directory on the server. Assume that the ListBox lists 2 directories & 4 files. Also assume that one of...
1
by: Alien | last post by:
Hi, I am new to PHP and trying to move a zip file from one directory to another. I researched on the web on this and all fingers pointed to this rename() function. I tried writing a PHP script...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.