473,699 Members | 2,438 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 3765
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
3763
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
2924
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
2073
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
2310
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
5053
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
9080
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
7142
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
7947
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
11010
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
9199
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
9054
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
7785
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
6550
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
5884
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
4391
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...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3075
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
2362
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.