473,790 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Unauthor izedAccessExcep tion when doing MoveTo()

Hi

I am trying to resolve this bug that I have in this application.
The code is below. It will generate this Exception

System.Unauthor izedAccessExcep tion: Access to the path is denied.
at System.IO.__Err or.WinIOError(I nt32 errorCode, String
maybeFullPath)
at System.IO.__Err or.WinIOError()
at System.IO.FileI nfo.MoveTo(Stri ng destFileName)
at ftpprogram_ns.f tpprogram..ctor ()

// csc /reference:Chilk atDotNet2.dll /target:exe /optimize+ /nologo
ftpprogram.cs
using System;
using System.Text;
using System.Xml;
using System.Data;
using System.Data.Ole Db;
using System.Net;
using System.IO;
using System.Security ;
using System.Security .Permissions;
using Chilkat;

namespace ftpprogram_ns
{
public class ftpprogram
{

public ftpprogram()
{
try
{
PermissionSet fullTrust = new
PermissionSet(P ermissionState. Unrestricted);
fullTrust.Deman d();

// Make a reference to a directory.
DirectoryInfo di = new DirectoryInfo(@ "\\servername\s folder
\");
// DirectoryInfo di = new DirectoryInfo(@ "S:\");
// DirectoryInfo di = new DirectoryInfo(@ "E:\IF\");

// Get a reference to each file in that directory.
FileInfo[] fiArr = di.GetFiles();

// Display the names of the files.
foreach (FileInfo fri in fiArr)
{

String file = String.Format(@ "\\servername\s harename\{0}",
fri.Name);
// String file = String.Format(@ "S:\{0}", fri.Name);
// String file = String.Format(@ "E:\IF\{0}" , fri.Name);
Console.WriteLi ne(file);
bool uploadSuccessfu l = uploadFile(file , fri.Name);

// if upload is successfull move the file to archive
folder
if(uploadSucces sful == true)
{
FileInfo fInfo = new FileInfo (file);
String path = String.Format(@ "\\servername\A rchive
\{0}", fri.Name);
// String path = String.Format(@ "L:\{0}", fri.Name);
// String path = String.Format(@ "E:\Archive\{0} ",
fri.Name);
Console.WriteLi ne(path);
Console.WriteLi ne(fInfo.ToStri ng());
fInfo.MoveTo(pa th);
}

} // end of foreach
} // end of try
catch(Exception e)
{
Console.WriteLi ne(e);

}
} // Default Constructor


public bool uploadFile(Stri ng filepath, String filename)
{
try
{

Ftp2 ftp = new Ftp2();

bool success;

// Any string unlocks the component for the 1st 30-days.
success = ftp.UnlockCompo nent("Anything for 30-day trial");
if (success != true)
{
Console.WriteLi ne(ftp.LastErro rText);
return false;
}

ftp.Hostname = "hostname";
ftp.Username = "username";
ftp.Password = "password";
ftp.Passive = true;

// Connect and login to the FTP server.
success = ftp.Connect();
if (success != true)
{
Console.WriteLi ne(ftp.LastErro rText);
return false;
}

// Upload a file.
string localFilename;
localFilename = filepath;
string remoteFilename;
remoteFilename = filename;

success = ftp.PutFile(loc alFilename,remo teFilename);
if (success != true)
{
Console.WriteLi ne(ftp.LastErro rText);
return false;
}

ftp.Disconnect( );
Console.WriteLi ne("File " + filename + " Uploaded!");
return true;
} // end of try
catch(Exception e)
{
Console.WriteLi ne(e);
return false;

}
} // end of upload()
[STAThread]
public static void Main()
{

ftpprogram start = new ftpprogram();

} // end of Main()
} // end of class
} // end of namespace

Aug 2 '07 #1
1 4605
Hi,
Enable Impersation with admin userid and password.
nygiantswin2005 wrote:
Hi

I am trying to resolve this bug that I have in this application.
The code is below. It will generate this Exception

System.Unauthor izedAccessExcep tion: Access to the path is denied.
at System.IO.__Err or.WinIOError(I nt32 errorCode, String
maybeFullPath)
at System.IO.__Err or.WinIOError()
at System.IO.FileI nfo.MoveTo(Stri ng destFileName)
at ftpprogram_ns.f tpprogram..ctor ()

// csc /reference:Chilk atDotNet2.dll /target:exe /optimize+ /nologo
ftpprogram.cs
using System;
using System.Text;
using System.Xml;
using System.Data;
using System.Data.Ole Db;
using System.Net;
using System.IO;
using System.Security ;
using System.Security .Permissions;
using Chilkat;

namespace ftpprogram_ns
{
public class ftpprogram
{

public ftpprogram()
{
try
{
PermissionSet fullTrust = new
PermissionSet(P ermissionState. Unrestricted);
fullTrust.Deman d();

// Make a reference to a directory.
DirectoryInfo di = new DirectoryInfo(@ "\\servername\s folder
\");
// DirectoryInfo di = new DirectoryInfo(@ "S:\");
// DirectoryInfo di = new DirectoryInfo(@ "E:\IF\");

// Get a reference to each file in that directory.
FileInfo[] fiArr = di.GetFiles();

// Display the names of the files.
foreach (FileInfo fri in fiArr)
{

String file = String.Format(@ "\\servername\s harename\{0}",
fri.Name);
// String file = String.Format(@ "S:\{0}", fri.Name);
// String file = String.Format(@ "E:\IF\{0}" , fri.Name);
Console.WriteLi ne(file);
bool uploadSuccessfu l = uploadFile(file , fri.Name);

// if upload is successfull move the file to archive
folder
if(uploadSucces sful == true)
{
FileInfo fInfo = new FileInfo (file);
String path = String.Format(@ "\\servername\A rchive
\{0}", fri.Name);
// String path = String.Format(@ "L:\{0}", fri.Name);
// String path = String.Format(@ "E:\Archive\{0} ",
fri.Name);
Console.WriteLi ne(path);
Console.WriteLi ne(fInfo.ToStri ng());
fInfo.MoveTo(pa th);
}

} // end of foreach
} // end of try
catch(Exception e)
{
Console.WriteLi ne(e);

}
} // Default Constructor


public bool uploadFile(Stri ng filepath, String filename)
{
try
{

Ftp2 ftp = new Ftp2();

bool success;

// Any string unlocks the component for the 1st 30-days.
success = ftp.UnlockCompo nent("Anything for 30-day trial");
if (success != true)
{
Console.WriteLi ne(ftp.LastErro rText);
return false;
}

ftp.Hostname = "hostname";
ftp.Username = "username";
ftp.Password = "password";
ftp.Passive = true;

// Connect and login to the FTP server.
success = ftp.Connect();
if (success != true)
{
Console.WriteLi ne(ftp.LastErro rText);
return false;
}

// Upload a file.
string localFilename;
localFilename = filepath;
string remoteFilename;
remoteFilename = filename;

success = ftp.PutFile(loc alFilename,remo teFilename);
if (success != true)
{
Console.WriteLi ne(ftp.LastErro rText);
return false;
}

ftp.Disconnect( );
Console.WriteLi ne("File " + filename + " Uploaded!");
return true;
} // end of try
catch(Exception e)
{
Console.WriteLi ne(e);
return false;

}
} // end of upload()
[STAThread]
public static void Main()
{

ftpprogram start = new ftpprogram();

} // end of Main()
} // end of class
} // end of namespace
Aug 2 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3142
by: Doug Taylor | last post by:
Hi, I originally posted this in dotnet.security, but have moved it here by request: Hi, I am trying to programmatically add a user with read permissions to the DACL of a registry key. All appears to go well until I try to
4
4709
by: Jane | last post by:
I got the web application to open up the excel. It works fine on my development box. But when i moved it to the production server, I cannot get the Excel spreadsheet to open. I get System.UnauthorizedAccessException: Access is denied. I've granted full access for the excel file stored in the server, but still can't access it. Please help!
1
1849
by: Hal 9000 | last post by:
In c# we have a function that creates a virtual directory in IIS 6.0 using DirectoryServices API. The code looks like this: // log in to IIS DirectoryEntry rootDir = new DirectoryEntry("IIS://localhost/W3SVC/1/Root",ADMIN_USR,ADMIN_PSWD,AuthenticationTypes.Secure); // create a child virtual directory DirectoryEntry virtualDir = rootDir.Children.Add(name, rootDir.SchemaClassName); // set the virtual directory's physical path
0
2477
by: Efi | last post by:
Hi, We have a simple 3 tier application which its core application is VC++ 6.0 ATL COM running as a server application in the COM+. An asp pipe is in charge of handling the requests and passes it to the COM for processing. We are now trying to migrate the asp pipe to Asp.Net. When running the above configuration with Asp.Net on IIS 5.0 (W2K) we have no problems but when trying the do it on IIS 6.0 (W2K3) we are getting the following...
7
4804
by: Peter Afonin | last post by:
Hello, I'm using this code to access a network share from an asp.net page: Dim dir As DirectoryInfo = New DirectoryInfo("\\10.0.0.150\FormLib\") Dim files() As FileInfo = dir.GetFiles("*.eps") When I try to do it, I get this error: System.UnauthorizedAccessException: Access to the path
0
1793
by: masago | last post by:
Hi....how are you ?? they can help me to solve this problem ?? Access to the path = "c:\windows\microsoft.net\framework\v1.1.4322\Temporary ASP.NET = Files\reports\06639073\bbab30a7" is denied.=20 Description: An unhandled exception occurred during the execution of the =
4
1494
by: 101 | last post by:
I get a security error when trying to write out to an XMLSchema file "myDs.WriteXmlSchema(strXMLSchemaFile)". I am running XP SP2, No Domain, MS file and print sharing uninstalled. I was able to get past this by making ASPNET part of the Administrators group. I tried the Power User group (as well as others) to no avail. I also had to install MS file and print sharing in order to even add ASPNET as a member of the Administrator group (or...
0
2332
by: nime | last post by:
I've got a problem. I cannot debug my app. which one contains WebBrowser control. I found a resolution but it's for an ASP related problem. I couldn't find a correct "user" to give permisson then I've added Everyone and refreshed policies (gpupdate /force), restarted VB IDE but still got the problem. What is the "worker process" for VB IDE? CODE:
2
14379
by: job | last post by:
In a sharepoint setup using smartpart to load our user controls using enterprise blocks (data) we are getting some strange errors (logged to the event log). We dont get the error all the time. When we get the error CPU goes 100% We have been through all we can think of, but have not been able to locate the source to the error. Any suggestions?
0
9666
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
10413
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
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...
0
9986
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9021
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
7530
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
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3707
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
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.