473,657 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.IO.FileN otFoundExceptio n using file.copy

I had previously posted this on the security ng, but haven't had a hit so I
was wondering if someone here would be willing to take a stab. I am trying
to copy a file to a network drive. I can do it on the web server but not
from a client. Here is the code:

Dim impersonationCo ntext As
System.Security .Principal.Wind owsImpersonatio nContext
Dim currentWindowsI dentity As System.Security .Principal.Wind owsIdentity
currentWindowsI dentity
=CType(User.Ide ntity,System.Se curity.Principa l.WindowsIdenti ty)
impersonationCo ntext = currentWindowsI dentity.Imperso nate()
dim Temp as string="TestFil e"
File.Copy("\\My Server\Template .doc", "\\MyServer \" & Temp &".doc")

impersonationCo ntext.Undo()

I get the error "System.IO.File NotFoundExcepti on: Could not find file
\\Server\File.. ." when running it from the [authenticated] client browser.
I searched everywhere on the web and MSDN on this error but found nothing.
The error it occurs on the file copy statement The file.copy statement is
trying to copy a file on a different server than the web server.

Any help is appreciated.

P.S. The web server is a backup domain w2k controller also, and the asp.net
user had to be changed to IWAM_Machine.
Nov 18 '05 #1
2 3759
to copy to another server you need to impersonate a primary token, not an
impersonation. to quickly test this, on the actual server, run ie and test -
it should work because the principal will be a primary token, if not, turn
off anonymous.

to get around this, your code will need to logon as a domain account with
enough permission to do the copy.

-- bruce (sqlwork.com)

"Stephen Witter" <sw*****@enpath med.com> wrote in message
news:#X******** ******@tk2msftn gp13.phx.gbl...
I had previously posted this on the security ng, but haven't had a hit so I was wondering if someone here would be willing to take a stab. I am trying to copy a file to a network drive. I can do it on the web server but not
from a client. Here is the code:

Dim impersonationCo ntext As
System.Security .Principal.Wind owsImpersonatio nContext
Dim currentWindowsI dentity As System.Security .Principal.Wind owsIdentity currentWindowsI dentity
=CType(User.Ide ntity,System.Se curity.Principa l.WindowsIdenti ty)
impersonationCo ntext = currentWindowsI dentity.Imperso nate()
dim Temp as string="TestFil e"
File.Copy("\\My Server\Template .doc", "\\MyServer \" & Temp &".doc")

impersonationCo ntext.Undo()

I get the error "System.IO.File NotFoundExcepti on: Could not find file
\\Server\File.. ." when running it from the [authenticated] client browser.
I searched everywhere on the web and MSDN on this error but found nothing.
The error it occurs on the file copy statement The file.copy statement is
trying to copy a file on a different server than the web server.

Any help is appreciated.

P.S. The web server is a backup domain w2k controller also, and the asp.net user had to be changed to IWAM_Machine.

Nov 18 '05 #2
The funny thing is I have tried to run the process from every server, even
the one where the file resides (and where it is being copied to), and they
all give the same message, that is, that the file does not exist. The only
place it works is on the web server. Anonymous access is turn off on the web
site.

I added the following code to test it:

Dim FilePermission As New FileIOPermissio n(FileIOPermiss ionAccess.AllAc cess,
"\\MyServer\MyS hare\SomeDirect ory\Template.do c") FilePermission. Assert()
If System.IO.File. Exists("\\MySer ver\MyShare\Som eDirectory\Temp late.doc")
then
response.write( "OK User: ") response.write( User.Identity.N ame)
response.end
Else
Try
FilePermission. Demand()
response.write( "Exists But Access Denied , User: ")
response.write( User.Identity.N ame)
Catch se As Exception
response.write( "Realy doesn't exist")
End Try
End If

It always returns "Exists But Access Denied , User: DOMAIN\User"

Thanks for your reply though. I know these situations can be caused by alot
of different factors.
"bruce barker" <no***********@ safeco.com> wrote in message
news:u3******** ******@tk2msftn gp13.phx.gbl...
to copy to another server you need to impersonate a primary token, not an
impersonation. to quickly test this, on the actual server, run ie and test - it should work because the principal will be a primary token, if not, turn
off anonymous.

to get around this, your code will need to logon as a domain account with
enough permission to do the copy.

-- bruce (sqlwork.com)

"Stephen Witter" <sw*****@enpath med.com> wrote in message
news:#X******** ******@tk2msftn gp13.phx.gbl...
I had previously posted this on the security ng, but haven't had a hit so
I
was wondering if someone here would be willing to take a stab. I am

trying
to copy a file to a network drive. I can do it on the web server but

not from a client. Here is the code:

Dim impersonationCo ntext As
System.Security .Principal.Wind owsImpersonatio nContext
Dim currentWindowsI dentity As

System.Security .Principal.Wind owsIdentity
currentWindowsI dentity
=CType(User.Ide ntity,System.Se curity.Principa l.WindowsIdenti ty)
impersonationCo ntext = currentWindowsI dentity.Imperso nate()
dim Temp as string="TestFil e"
File.Copy("\\My Server\Template .doc", "\\MyServer \" & Temp &".doc")

impersonationCo ntext.Undo()

I get the error "System.IO.File NotFoundExcepti on: Could not find file
\\Server\File.. ." when running it from the [authenticated] client browser. I searched everywhere on the web and MSDN on this error but found nothing. The error it occurs on the file copy statement The file.copy statement is trying to copy a file on a different server than the web server.

Any help is appreciated.

P.S. The web server is a backup domain w2k controller also, and the

asp.net
user had to be changed to IWAM_Machine.


Nov 18 '05 #3

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

Similar topics

1
3762
by: | last post by:
I still have big problems running an assembly consisting of C# generated dll and exe and VC++ (managed+unmanaged+mfc) generated dll. On my development machine no problem, but on any other machine. I get an System.IO.FileNotFoundException for one of my dll's. The odd thing is that the file is right there, the file have the correct version and in the error messages you can clearly see that he does know where to look for the file. So in...
1
2919
by: Brian | last post by:
I've looked through the previous posts on this one and have verified permissions and location of my Dlls, but I am still getting an exception when I try to Load an assembly. The directory where my Dlls are located give the ASPNET user full control, and all Dlls used by the Assembly in question are in the local folder with the rest of the web application Dlls. Could someone take a look at my error and shed some light on this?
3
2071
by: Karl Hungus | last post by:
A cs file I compiled into an assembly dll is in my bin directory. In the cs file I have a using statement for System.Xml I compiled it using this command: csc /out:XmlContent.dll /t:library XmlContent.cs When I run my aspx page, which has a codebehind that instantiates the object from in my assembly, I get the following error, anyone know why? File or assembly name System.Xml, or one of its dependencies, was not found.
2
2309
by: aallee83 | last post by:
i'm new in asp.net after develop my solution i copied it on the server where I want it to run but something cares... WHAT?!?! thank you in advance File or assembly name System, or one of its dependencies, was not found. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
1
5050
by: Olav Tollefsen | last post by:
I get the included error message when trying to run my ASP.NET application under Windows Server 2003 (with all updates installed). How can I troubleshoot this? Olav File or assembly name System.Xml, or one of its dependencies, was not found. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information
3
9075
by: James | last post by:
Hi guys Do you ever get the exception in Managed C++? How can I know which file or dll is missed?
1
7140
by: kkizer | last post by:
I have a problem with this simple code below. Moving the files works perfectly, but once in a blue moon the file that it is trying to move dissapears before it can move it. and when this happens the "System.IO.Move" goes in to a loop and keeps creating the file on the destination folder with a 0byte size and keeps entering the error in the log i have until someone stop the service. so what i cant figure out is since it catches the...
2
7941
by: jjlagtap | last post by:
Hey everyone When I try to open a file i get the Exception listed below. The weird thing is it works when I run the web app locally and when i use a remote server and open a file on my computer. When someone else uses the web app and tries to open a file using the remote server the error below happens. any help? **Code** C# - filepath is a valid file name which is passed via the form. System.IO.BinaryReader br = new...
2
11007
by: =?Utf-8?B?c2FtMDFt?= | last post by:
I have a remoting application that was developed on a Windows XP SP2 machine with VS2005 SP1. I finally got everything deployed using Wix 3.0, and it works great. Problem is, when I install the msi on a W23 server SP2, I get the following error: System.Runtime.Remoting.RemotingException: Remoting configuration failed with the exception 'System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation....
0
8407
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
8739
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
8512
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
7347
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...
0
5638
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
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
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.