473,438 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,438 software developers and data experts.

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\ObjectList.zip";
string sTarget = @"\\nasrv88c3\modeldev$\modeldev\apps\\ObjectList. zip"

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

It fails with "System.Io.FileNotFoundException: 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 43031
Hi

It works alright for me in C#.

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

Cheers
Shane Sukul
MCSD MCAD

"Gravitation 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\ObjectList.zip";
string sTarget = @"\\nasrv88c3\modeldev$\modeldev\apps\\ObjectList. zip"

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

It fails with "System.Io.FileNotFoundException: 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\modeldev$\modeldev\apps\\ObjectList. 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

"Gravitation 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\ObjectList.zip";
string sTarget = @"\\nasrv88c3\modeldev$\modeldev\apps\\ObjectList. zip"

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

It fails with "System.Io.FileNotFoundException: 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\modeldev$\modeldev\apps\\ObjectList. zip"
may be should be
@"\\nasrv88c3\modeldev$\modeldev\apps\ObjectList.z ip"
There are \\ObjectList.zip 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$\modeldev\apps\\ObjectList .zip"
may be should be
@"\\nasrv88c3\modeldev$\modeldev\apps\ObjectList. zip"
There are \\ObjectList.zip 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\modeldev$\modeldev\apps\\ObjectList. zip",

"modeldev$" is a share name.

You will have to use the fully qualified name of the
destination folder. For example:
@"\\nasrv88c3\modeldev\myModule\modeldev\apps\\Obj ectList.zip",

HTH

Regards
Shane Sukul
MCSD MCAD

"Frank Rizzo" wrote:
GG wrote:
Not sure if it helps but
@"\\nasrv88c3\modeldev$\modeldev\apps\\ObjectList .zip"
may be should be
@"\\nasrv88c3\modeldev$\modeldev\apps\ObjectList. zip"
There are \\ObjectList.zip 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$\modeldev\apps\\ObjectList .zip",

"modeldev$" is a share name.

You will have to use the fully qualified name of the
destination folder. For example:
@"\\nasrv88c3\modeldev\myModule\modeldev\apps\\Ob jectList.zip",


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
@"\\nasrv88c3\modeldev$\modeldev\apps\\ObjectLi st.zip"
may be should be
@"\\nasrv88c3\modeldev$\modeldev\apps\ObjectLis t.zip"
There are \\ObjectList.zip 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\somefile.txt"
try
{

File.Copy(sSource, sTarget);

}
catch (Exception ex )
{
try
{
// Map a drive
System.Diagnostics.Process.Start(@"C:\WINDOWS\syst em32\net.exe",
@"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(sSource, sTarget);

}
catch (Exception ex2)
{
MessageBox.Show(ex2.ToString());
}
finally
{
// Delete the mapped drive
System.Diagnostics.Process.Start(@"C:\WINDOWS\syst em32\net.exe",
"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
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...
0
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...
8
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...
8
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,...
2
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...
0
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...
10
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...
4
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...
0
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...
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.