473,786 Members | 2,795 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to fix Access to the path '...' is denied. error in C#

1 New Member
I'm on windows 7 creating a desktop aplication in Visual C# 2010.
The error's produced here:

Expand|Select|Wrap|Line Numbers
  1. void Copymove(string file) 
  2. {
  3.  File.Copy(Environment.GetFolderPath(Environment.SpecialFold er.MyDocuments), "../../contenidos/" + file);
  4. }
  5.  
The exact error:
Access to the path 'C:\Users\Danie l\Documents' is denied.

I've already tried modifying the app.manifest and it does not work... It's been about 4 hours i've been trying to fix this. Any ideas?

Thanks in advance.
Jun 24 '12 #1
1 27997
Aimee Bailey
197 Recognized Expert New Member
Firstly your trying to copy the entire My Documents folder into a file, that can't be done like that, File.Copy(..) is used to copy a single file, so make sure the parameters are correct.

Secondly Windows 7 is picky with how you access files, and for the most part will deny access to anything on the primary drive it deems important.

Here is method that you can use that manually copies a file, hopefully this will help show how the File.Copy method works, remember to always pass a full filename in for fileFrom and fileTo:

Expand|Select|Wrap|Line Numbers
  1. void FileCopy(string fileFrom, string fileTo, long bufferSize = 1024)
  2. {
  3.     byte[] buffer = new byte[bufferSize];
  4.     using (FileStream inStream = new FileStream(fileFrom, FileMode.Open, FileAccess.Read, FileShare.Read))
  5.     {
  6.         using (FileStream outStream = new FileStream(fileTo, FileMode.Create, FileAccess.Write, FileShare.Write))
  7.         {
  8.             while (inStream.Position < inStream.Length - buffer.Length)
  9.             {
  10.                 inStream.Read(buffer, 0, buffer.Length);
  11.                 outStream.Write(buffer, 0, buffer.Length);
  12.             }
  13.  
  14.             // Copy the remaining part.
  15.             buffer = new byte[inStream.Length - inStream.Position];
  16.             inStream.Read(buffer, 0, buffer.Length);
  17.             outStream.Write(buffer, 0, buffer.Length);
  18.         }
  19.     }
  20. }
  21.  
example usage:

Expand|Select|Wrap|Line Numbers
  1. string myDocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
  2. string fileIn = Path.Combine(myDocs, "stuff.txt");
  3. string fileOut = "e:\\stuff.txt";
  4. FileCopy(fileIn, fileOut);
  5.  
Aimee.
Jun 25 '12 #2

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

Similar topics

5
2099
by: Brent Burkart | last post by:
Has anyone seen the following error? My application was working fine and this error just showed up this morning. Any help is appreciated? System.Security.Principal.WindowsIdentity._ResolveIdentity(IntPtr userToken) +0 System.Security.Principal.WindowsIdentity.get_Name() +71 System.Web.Configuration.AuthorizationConfigRule.IsUserAllowed(IPrincipal user, String verb) +100...
5
1699
by: David | last post by:
I'm developing an ASP.NET application to run on Win2K server with IIS 5.1, which has run perfectly happily in various development, test and staging environments. I've recently deployed it on one of our production servers and I'm getting an intermittent 'Access is denied' error when pages are loading. The file being accessed is an xml globalisation file that is used to load the text for the page according to the language settings of the...
5
2069
by: Don Hans | last post by:
Gents, Have .Net2003 Enterprise architect installed on a Win2k Server with IIS. Even logged in as administrator, I cannot run any ASP.NET app with debugging. I always get the error "Unable to start debugger on the web server: Access is Denied" when attempting to start the app with debugging. Now, I have already spent 3 days going through every Knowledge base article and all the included help with .net, have tried about 50 different...
6
5400
by: Kevin Quigley | last post by:
Hi, I have a configuration file which stores sql server connection details and some other application data, stored in a directory. When I try to access this file in my code, I get the following error.... Access to the path "D:\WEBSERVER\WeeklyReport\Config\Accounts.Config" is denied. I have gave the ASPNET user full permissions on the directory and
1
1097
by: Edward | last post by:
ASP.NET on VS2003. I have been developing the application for some months, and delivering incremental releases in the form of new DLLs (for code changes), or new .aspx pages for client changes. Yesterday I sent the client a new DLL and an aspx page. This morning I have had them complaining bitterly because they are getting "Access is denied" errors.
2
5087
by: ajain1008 | last post by:
I'm running the following code on asp.net form Dim objExcel As Excel.Application Dim objWrkBk As excel.Workbook objExcel = New excel.Application objWrkBk = objExcel.Workbooks.Open("C:\Inetpub\wwwroot\ret\ret.xls") objWrkBk.Close(SaveChanges:=True) objWrkBk = Nothing objExcel.Quit() objExcel = Nothing
1
14091
by: sahan malagi | last post by:
Hello, I am new to webservices and I am trying to get a simple Webservice client in VB (Using Microsoft SOAP Toolkit) to access a webservice on a public site. I get the following error message when I run my webservice client... Runtime Error '-2147024809 (80070057) WSDLReader: Loading of the WSDL file failed HRESULT=0x80070057 WSDLReader:XML Parser failed at linenumber 0, lineposition 0, reason is:Access is denied. HRESULT:0x80070005
3
1213
by: Ayoa | last post by:
I have a COM Component (VB6) which i am trying to use in my ASP.Net App. I have already successfully used it in a c# windows app. But when i attempt to use it in my ASP.net app it throws an "System.UnauthorizedAccessException: Access is denied" exception on the initialisation line. i.e. PMerger.clsPMergerClass oPdf = new PMerger.clsPMergerClass(); in my Web.config file i have authentication mode to be "windows" and identity impersonate...
2
8032
by: Paolo | last post by:
Hi to all, I have an error that drove me crazy. Try the following page that should only allow to upload a file: <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body>
6
4497
Carrugar
by: Carrugar | last post by:
I'm running IIS 6.0 on a Win2003 server. One web page is trying to use the new CDO method of sending e-mail but generates the following error: CDO.Message.1 error '80070005' Access is denied. Code: <%
0
9650
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8992
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6748
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.