473,387 Members | 1,890 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.

To search a file and to copy it from server

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 search.like 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
searchfolder="y:\\Template\\else";
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+"*");
if(files.Length==1)
{
foreach (string dir in files)
{
lblcnt.Text="Selected File: "+ dir;
string[] search = Directory.GetFiles(destination,"mod501-"+filetosearch+".3d");
if(search.Length>0)
{
lblcnt.Visible=true;
lblcnt.Text="File already exist";
}
else
{
File.Copy(source,target);
lblcnt.Visible=true;
lblcnt.Text="File copied";
}
}

what to give insted of
searchfolder="y:\\Template\\else";

If am using
searchfolder="@books\\template\\Template\\else";
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
2 1661
file.copy(source.target)
server shhould be
string source="\\\\server\\folde\\";
Sep 18 '07 #2
Plater
7,872 Expert 4TB
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

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

Similar topics

1
by: Luke Dalessandro | last post by:
I have an application where there is a primary XML data file. I'll use the following as an example: <data> <item id="a"> <name>A</name> <price>$10</price> </item> <item id="b">...
2
by: Stephen Witter | last post by:
I had previously posted this on the security ng, but haven't had a hit so I was wondering if someone here would be willing to take a stab. I am trying to copy a file to a network drive. I can do...
8
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my...
9
by: CGW | last post by:
I asked the question yesterday, but know better how to ask it, today: I'm trying to use the File.Copy method to copy a file from a client to server (.Net web app under IIS ). It looks to me that...
0
by: Chung Leong | last post by:
Here's a short tutorial on how to the OLE-DB extension to access Windows Indexing Service. Impress your office-mates with a powerful full-text search feature on your intranet. It's easier than you...
8
by: rempit | last post by:
Hye all..I'm Newbie.. I'm using asp.net..This code below I put in .aspx file..And become like that.. I want to make something like "WHEN USER PUT SOMETHING IN TEXTBOX AND CLICK THE BUTTON...
2
by: princymg | last post by:
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...
9
by: fniles | last post by:
I would like to copy a table(s) from SQL Server 2005 to a CVS file and vice versa. I was thinking to use the BCP command line utility, but I have a few questions: 1. The machine where I am...
1
by: mravik | last post by:
Hi All, I have different subsystems in my application, if one is down it will through some error message in log file. I have a collection of error messages in another file and I want to check each...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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.