473,769 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Copying a file to a network share

Hello, I've asked this question in the languages.vb group, but got no
response, so I'll try my luck here.

My app needs to copy a file from a local folder to a network share. The
network share is accessible via a domain ID, which has all possible
folder rights assigned to it. The domain ID also has full rights to the
local folder. I am using the impersonation code from here

http://msdn.microsoft.com/library/de...asp?frame=true

The code seems to properly impersonate (as evidenced by debug
statements), however, when I do this:

string sSource = @"c:\temp\Objec tList.zip";
string sTarget = @"\\nasrv88c3\m odeldev$\modeld ev\apps\\Object List.zip"

Try
File.Copy(sSour ce, sTarget)
Catch ex As Exception
MessageBox.Show (ex.ToString)
End Try

It fails with "System.Io.File NotFoundExcepti on: Could not find the
file..." I know for sure that the file is there. Do I first perhaps
have to log on to the share? If so, are there any examples out there?
What am I missing in general?

Thank you

Nov 16 '05 #1
7 43149
Hi

It works alright for me in C#.

I think the pblm is that the line:
string sTarget = @"\\nasrv88c3\m odeldev$\modeld ev\apps\\Object List.zip"
is referencing a file share. Try using a UNC name and you should be fine.

Cheers
Shane Sukul
MCSD MCAD

"Gravitatio n is not responsible for people falling in love" - Albert Eistein

"Frank Rizzo" wrote:
Hello, I've asked this question in the languages.vb group, but got no
response, so I'll try my luck here.

My app needs to copy a file from a local folder to a network share. The
network share is accessible via a domain ID, which has all possible
folder rights assigned to it. The domain ID also has full rights to the
local folder. I am using the impersonation code from here

http://msdn.microsoft.com/library/de...asp?frame=true

The code seems to properly impersonate (as evidenced by debug
statements), however, when I do this:

string sSource = @"c:\temp\Objec tList.zip";
string sTarget = @"\\nasrv88c3\m odeldev$\modeld ev\apps\\Object List.zip"

Try
File.Copy(sSour ce, sTarget)
Catch ex As Exception
MessageBox.Show (ex.ToString)
End Try

It fails with "System.Io.File NotFoundExcepti on: Could not find the
file..." I know for sure that the file is there. Do I first perhaps
have to log on to the share? If so, are there any examples out there?
What am I missing in general?

Thank you

Nov 16 '05 #2
Shailen Sukul wrote:
Hi

It works alright for me in C#.

I think the pblm is that the line:
string sTarget = @"\\nasrv88c3\m odeldev$\modeld ev\apps\\Object List.zip"
is referencing a file share. Try using a UNC name and you should be fine.

What do you mean. The path is in UNC format?
Cheers
Shane Sukul
MCSD MCAD

"Gravitatio n is not responsible for people falling in love" - Albert Eistein

"Frank Rizzo" wrote:
Hello, I've asked this question in the languages.vb group, but got no
response, so I'll try my luck here.

My app needs to copy a file from a local folder to a network share. The
network share is accessible via a domain ID, which has all possible
folder rights assigned to it. The domain ID also has full rights to the
local folder. I am using the impersonation code from here

http://msdn.microsoft.com/library/de...asp?frame=true

The code seems to properly impersonate (as evidenced by debug
statements) , however, when I do this:

string sSource = @"c:\temp\Objec tList.zip";
string sTarget = @"\\nasrv88c3\m odeldev$\modeld ev\apps\\Object List.zip"

Try
File.Copy(sSour ce, sTarget)
Catch ex As Exception
MessageBox.Show (ex.ToString)
End Try

It fails with "System.Io.File NotFoundExcepti on: Could not find the
file..." I know for sure that the file is there. Do I first perhaps
have to log on to the share? If so, are there any examples out there?
What am I missing in general?

Thank you

Nov 16 '05 #3
GG
Not sure if it helps but
@"\\nasrv88c3\m odeldev$\modeld ev\apps\\Object List.zip"
may be should be
@"\\nasrv88c3\m odeldev$\modeld ev\apps\ObjectL ist.zip"
There are \\ObjectList.zi p instead of 1



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4
GG wrote:
Not sure if it helps but
@"\\nasrv88c3\ modeldev$\model dev\apps\\Objec tList.zip"
may be should be
@"\\nasrv88c3\ modeldev$\model dev\apps\Object List.zip"
There are \\ObjectList.zi p instead of 1

Oh, i am sorry, that was just a typo. There is a single slash, not a
double one.
Nov 16 '05 #5
By UNC I mean a fully-qualified name to the network folder. For example,

in the line:

@"\\nasrv88c3\m odeldev$\modeld ev\apps\\Object List.zip",

"modeldev$" is a share name.

You will have to use the fully qualified name of the
destination folder. For example:
@"\\nasrv88c3\m odeldev\myModul e\modeldev\apps \\ObjectList.zi p",

HTH

Regards
Shane Sukul
MCSD MCAD

"Frank Rizzo" wrote:
GG wrote:
Not sure if it helps but
@"\\nasrv88c3\ modeldev$\model dev\apps\\Objec tList.zip"
may be should be
@"\\nasrv88c3\ modeldev$\model dev\apps\Object List.zip"
There are \\ObjectList.zi p instead of 1

Oh, i am sorry, that was just a typo. There is a single slash, not a
double one.

Nov 16 '05 #6
Shailen Sukul wrote:
By UNC I mean a fully-qualified name to the network folder. For example,

in the line:

@"\\nasrv88c3\ modeldev$\model dev\apps\\Objec tList.zip",

"modeldev$" is a share name.

You will have to use the fully qualified name of the
destination folder. For example:
@"\\nasrv88c3\ modeldev\myModu le\modeldev\app s\\ObjectList.z ip",


The point is that I don't know what the fully qualified name is. How
can I copy the file in that case?
HTH

Regards
Shane Sukul
MCSD MCAD

"Frank Rizzo" wrote:
GG wrote:
Not sure if it helps but
@"\\nasrv88c 3\modeldev$\mod eldev\apps\\Obj ectList.zip"
may be should be
@"\\nasrv88c 3\modeldev$\mod eldev\apps\Obje ctList.zip"
There are \\ObjectList.zi p instead of 1

Oh, i am sorry, that was just a typo. There is a single slash, not a
double one.

Nov 16 '05 #7
Ok, in the case where you have to map a shared drive using different user
credentails(if necessary), do the following:

sTarget = "\\some server\some share$\somefile .txt"
source = "c:\temp\somefi le.txt"
try
{

File.Copy(sSour ce, sTarget);

}
catch (Exception ex )
{
try
{
// Map a drive
System.Diagnost ics.Process.Sta rt(@"C:\WINDOWS \system32\net.e xe",
@"use J: \\some server\some share$ password /user:someuser") ;

// Delay to allow the changs to take effect
for (int i =0;i<10000;i++)

File.Copy(sSour ce, sTarget);

}
catch (Exception ex2)
{
MessageBox.Show (ex2.ToString() );
}
finally
{
// Delete the mapped drive
System.Diagnost ics.Process.Sta rt(@"C:\WINDOWS \system32\net.e xe",
"use j: /delete");
}
}

Regards
Shane Sukul
MCSD MCAD

Nov 16 '05 #8

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

Similar topics

3
3656
by: Robert Tarantino | last post by:
Hello, I am trying to find a way to create a scheduled task or service that will copy my local profile folders under "Documents and settings" to a network drive. This would allow me to restore my settings if my profile became tampered with or corrupt. Is there any sample code available out there? -Robert
0
1584
by: surya | last post by:
Hi, I need to enable shadow copying network share folder assemblies. Currently if the path is given as the network share folder path, shadow copying is not enabled. Should something special be done to enable shadow copying of files on network share folders? Thanks in advance, Regards Surya
8
17038
by: Ram Baruch | last post by:
Hi, I'm trying to use the File.Copy() function. It works well when the desenation file is local (Like: C:\dest\dest.exe). The problem is that when I'm trying to copy to a destenation that starts with '\\' it doesnt work and exception is thrown (for example: \\MyComputer\DestDirectory). Even if the first and the second directories are actually the same- the File.Copy() doesn't work. Is there any way to copy a file to a different computer?...
8
11853
by: Lam | last post by:
HI anyone knows how can I open a mapped network file in C#? I try string file = @"T:\file.txt"; it shows me the error: "Could not find a part of the path" but if I copy the file to my C dirve, and use @"C:\file.txt"; it worked Thanks a lot
2
2184
by: Frank Rizzo | last post by:
Hello, my app needs to copy a file from local TEMP folder to network share. The network share is accessible via a domain ID. I am trying to call LogonUser API, then ImpersonateLoggedOnUser, then copy the file to this share. But I keep on getting errors. Even though all the APIs return success, copying files still comes back with "Access denied" type of errors. Am I missing something here? Thanks
0
1339
by: Frank Rizzo | last post by:
Hello, my app needs to copy a file on a network share. The network share is accessible via a domain ID, which has all possible folder rights assigned to it. I am using the impersonation code from here http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityPrincipalWindowsImpersonationContextClassTopic.asp?frame=true The code seems to properly impersonate (as evidenced by debug statements),...
10
7838
by: Martin Ho | last post by:
I am running into one really big problem. I wrote a script in vb.net to make a copy of folders and subfolder to another destination: - in 'from.txt' I specify which folders to copy - in 'to.txt' I specify where to copy it - After I read content of 'to.txt' I create one more subfolder named by current date and thats where everything gets to be copied
4
3135
by: Sue | last post by:
Hello We have an application where the user would upload files (max size of 200 mb) from their client machine. This application will run on a web server (its a web server which would be used by the general public), because of obvious reason, this server will not have access to any shared directory on the network. Currently we store the file on the local drive (c:) of that server and an other application running on an internal server...
0
1746
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hi, We have a legacy asp application that uses a third party component to upload a file and saves it to a secure network share. The code sets the credentials for the secure network share on the third party component. I want to do something similar from C# code and save a file to the secure network share by setting the credentials to access the network share in code rather than running the C# code under the user account that has access...
0
2045
by: cw808 | last post by:
Hi all. I'm new here but hoping I can get some help for my problem. My situation is that I need to upload files through a C# .NET web application to a file server. I done a search and followed some advice on how to set it up. My environment is Windows 2003 file server, Windows 2000 web service (IIS) and .NET v1.1.4. So far I've done this. Windows 2003 file server: Created an account SHAREUSER. Created a share MEDIA. SHAREUSER is...
0
9579
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
9422
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
10038
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
9987
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
6662
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
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3952
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
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2812
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.