By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,978 Members | 1,362 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,978 IT Pros & Developers. It's quick & easy.

To search a file and to copy it from server

P: 7
I want to search a file from server and want to copy it to the local disk.
how it is done? This is working if the file is in my hard disk itself.But not when it comes to server. If i map the server i can y:\\serverfolde\\folder am tring to make an exe. different people will map to different drive. so i cant give like that.should give like @\\server\\serverfolde\\folder\\ but it is not working.
My code is
destination ="D:\\Princy\\My Documents\\project\\";
string source=searchfolder+"\\"+"mod501_"+filetosearch+". 3d";
string target=destination+"mod501-"+filetosearch+".3d";
string[] files = Directory.GetFiles(searchfolder, "mod501_"+filetosearch+".3d");
//string[] files = Directory.GetFiles(searchfolder, filetosearch+"*");
foreach (string dir in files)
lblcnt.Text="Selected File: "+ dir;
string[] search = Directory.GetFiles(destination,"mod501-"+filetosearch+".3d");
lblcnt.Text="File already exist";
lblcnt.Text="File copied";

what to give insted of

If am using
am geting error:
System.IO.DirectoryNotFoundException:Could not find a part of the "@books\template\Template\els".
Otherwise its working perfectly.
Sep 17 '07 #1
Share this Question
Share on Google+
2 Replies

P: 7
server shhould be
string source="\\\\server\\folde\\";
Sep 18 '07 #2

Expert 5K+
P: 7,872
well in C# if you put an @ before a string everything is literals so a
string mystr=@"\\server\myshare\file.txt";
will actually BE \\server\myshare\file.txt

But if you can access the shares in that manor from say a Start->Run box, then you should be able to in code. The only problem might be log-in credentials versus running user credentials?
(ie your program might be trying to "log in" to that directory with a dis-allowed ser of credentials)
Sep 18 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.