473,387 Members | 1,481 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,387 software developers and data experts.

C# file copy to UNC path

How does one copy a file to a UNC path and include authentication?

My current code is:

System.IO.File.Copy(@"c:\picture.jpg", @"\\server\share\picture.jpg");

Of course I just get a login failed for this, as I don't know how to
transmit authentication information with the request.

Anyone know how to do this?
Nov 16 '05 #1
1 21214
The "right" way to do this is probably to grant the principle the proper
access rights, however if you've ruled that out and are willing to
accept the security implications involved, you could issue a "net use"
command via System.Diagnostics.Process.Start(...) prior to trying to
copy the file. You can find the syntax for it by typing:

net use /?

at the command line. I believe that once it has been issued the system
will cache the access rights (wrong term... right concept) and allow
access to the machine for subsequent calls. You'll have to try it out
to know for sure but I think this just might do it.

Anyone know of another way to do this that doesn't feel so "wrong?"

Have A Better One!

John M Deal, MCP
Necessity Software

BLiTZWiNG wrote:
How does one copy a file to a UNC path and include authentication?

My current code is:

System.IO.File.Copy(@"c:\picture.jpg", @"\\server\share\picture.jpg");

Of course I just get a login failed for this, as I don't know how to
transmit authentication information with the request.

Anyone know how to do this?

Nov 16 '05 #2

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

Similar topics

0
by: Tess | last post by:
Hi, Long time reader, first time poster... Any help is appreciated. I have a few questions regarding Winform controls embedded within an html page. For more info please see the appendix. Now,...
0
by: SeanR | last post by:
I have a function to copare two files. It will first copy the original file form a different server to a local temp path and then compare that version to a version that has been restored form tape....
2
by: Greg | last post by:
looking for an easy way for users to browse for a file on their local drive, and then have access automatically make a copy of that file (files will most likely be images) and save it under a new...
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...
5
by: Washington | last post by:
Is possible to copy file from some server for. e.g. brinkster to computer (on specified location) programmatically? I am trying to make some automatic update of my application... Thanks :)
2
by: Pete Davis | last post by:
I'm getting an exception when trying to copy a file. I basically do a File.Copy(source, dest, false); source is the source full path and filename. dest is the destination full path and...
3
by: Bala | last post by:
Hi From my aspx page i am calling one of the console.exe. that exe will copy the file from network to local webserver. everything hardcoded path. I given all the permission to that exe. I am...
1
by: Dan | last post by:
I have an application that I want to use for copying files. My goal is to copy a files, if a file is in use or not accessible because of security reasons I want to make note of that file then...
5
by: Saabster | last post by:
Hi all, It's always the simple stuff that trips you up I guess. Here is the issue I'm dealing with. I have a folder with 1400 excel files that I need to move to another location. Since each...
3
by: =?Utf-8?B?R2FuZXNoYQ==?= | last post by:
Hi I would like to use File.Copy with UNC paths. I have seen this problem reported by others as well. Can i use File.Copy with UNC paths. ie., i would like to copy a file from one of the folder to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.