473,772 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:\pictu re.jpg", @"\\server\shar e\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 21350
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.Diagnost ics.Process.Sta rt(...) 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:\pictu re.jpg", @"\\server\shar e\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
2598
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, for the questions. 1. A button on my control executes the System.IO.Directory.GetDirectories funtion (the scanned directory resides on the hosting web server). What credentials is this
0
2104
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. Once the compare is complete the file that was copied to a temp location needs to be deleted. I am using the method file.copy(sourcePath, tempPath, true) to copy the file and then file.delete(tempPath) to delete the file. On some of the files...
2
9353
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 name (somehow relating it to the PK of the main table) in a directory on the server where the DB is stored... i realize that might not be the best wording of what im trying to do, so ill try explaining it a lil differently. each record created...
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?...
5
1222
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
5509
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 filename. The file actually appears to copy just fine. The problem is it throws an IOException with the message:
3
1525
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 getting below error on last line what am i doing wrong here. Could not find file "\\laptop02\temp\test.pdf".
1
2739
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 continue with the file copy process. For some reason when my app is copying the C:\Windows\System32\Config folder it will fail on the first non-accessible file then ends the copy process. It only seems to happen on this folder (folder contains...
5
3264
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 file has to go in to a particular target folder I decided that writing a program to move the files is they way to go. I've got all but this last piece down. and for the life of me I can't
3
5151
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 a shared folder. eg., File.Copy(srcPath, "\\machinename\\folder) This is giving an error "Could not find part of the path \\machinename\\folder" Is this feature supported? if yes please can anyone let me knwo how to
0
9619
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
9454
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
9911
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7460
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
6713
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
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
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.