C# copy files methods for all possible drive

B

Bandu

Hi,

What would be the best method to copy files that will work for all the
following scenario?
1. Local Drive (obviously)
2. Network Mapped drive
3. from ip address ( e.g. \\192.168.0.1\myshare)

I know file.Copy() but it didn't work properly with network mapped
drive or ip address.

Help, please.

Regards,

Bandu
 
P

Peter Duniho

Hi,

What would be the best method to copy files that will work for all the
following scenario?
1. Local Drive (obviously)
2. Network Mapped drive
3. from ip address ( e.g. \\192.168.0.1\myshare)

I know file.Copy() but it didn't work properly with network mapped
drive or ip address.

Define "didn't work properly". In what way did it not work properly?

File.Copy() should work on any volume, network or not. But without a
concise-but-complete code example from you that reliably demonstrates the
problem, along with a precise description of what didn't work and in what
way, it's not possible to suggest what you might need to fix.

Pete
 
B

Bandu

Define "didn't work properly".  In what way did it not work properly?

File.Copy() should work on any volume, network or not.  But without a  
concise-but-complete code example from you that reliably demonstrates the 
problem, along with a precise description of what didn't work and in what 
way, it's not possible to suggest what you might need to fix.

Pete

"Didn't work properly" => If I use it in "Win Form" and tested against
copying network mapped drive, it work fine. But if I put that method
into setup's custom installer to execute, it gave me security
exception. I even try to put that method into separate winform exe and
try to execute it from customer installer also gave me exception.

All the sample I can found on internet about copying from network
drive need security or permission setup, which need user name and
password. But in my case, its not suitable.

I even try "cmd /K xcopy ...", it worked fine executing from other
winform application. But if I put it in custom installer, it gave me
invalid drive error message. According to my experience, using XCopy
from command line or execute it from winform, works every times with
all type of drives. But now I got a problem executing from customer
installer.

Thanks.

Bandu
 
P

Peter Duniho

"Didn't work properly" => If I use it in "Win Form" and tested against
copying network mapped drive, it work fine. But if I put that method
into setup's custom installer to execute, it gave me security
exception. I even try to put that method into separate winform exe and
try to execute it from customer installer also gave me exception. [...]

Your problem description is still vague, and doesn't include a
concise-but-complete code example that reliably demonstrates the problem.
But, from what you've written so far, I'd guess that you're simply running
into the basic issue that certain accounts on Windows aren't allowed to
access network shares. Like, the account your custom install is running
under.

You may be able to work-around the restriction by authenticating as a user
that does have permission to use network shares. You'll have to prompt
the user and they'll have to enter their password. Unfortunately, I don't
have specifics on the exact code you'll need; MSDN should be able to help
you find the documentation you need, if that's in fact the right way to
address your issue.

Pete
 
B

Bandu

"Didn't work properly" => If I use it in "Win Form" and tested against
copying network mapped drive, it work fine. But if I put that method
into setup's custom installer to execute, it gave me security
exception. I even try to put that method into separate winform exe and
try to execute it from customer installer also gave me exception. [...]

Your problem description is still vague, and doesn't include a  
concise-but-complete code example that reliably demonstrates the problem. 
But, from what you've written so far, I'd guess that you're simply running  
into the basic issue that certain accounts on Windows aren't allowed to  
access network shares.  Like, the account your custom install is running  
under.

You may be able to work-around the restriction by authenticating as a user  
that does have permission to use network shares.  You'll have to prompt 
the user and they'll have to enter their password.  Unfortunately, I don't  
have specifics on the exact code you'll need; MSDN should be able to help 
you find the documentation you need, if that's in fact the right way to  
address your issue.

Pete


Hi Pete,

Thanks. I'll dig more and let you know.

regards,

Bandu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top