Click here to Skip to main content
14,691,808 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
ı want to do download or copy any type of file from server 2008 to local machine ı wrote this code but not work
string path = @"\\servername\\doc\\'"+TextBox1.Text+"'";textbox1.text include file name
string path2 = @"c:\";
System.IO.FileInfo fi1 = new System.IO.FileInfo(path);
fi1.CopyTo(path2);

very important point here there is a directory location on the server.
for ex
in the server c:/xxxx/xxxx/doc/xxx.txt or xxx.doc or xxx.pdf ı want to say that doc file allow for all users.
ı want to download or copy from this location to local machine c:/ directory
Posted
Updated 28-Dec-11 0:57am
v2
Comments
Wendelius 28-Dec-11 5:57am
   
pre tags added

In order to "copy" a file from a server to the local machine, the server has to share the drive/folder in question (and you will probably have to configure permissions in order to access the share). If you're talking about downloading via a web page, you need to configure IIS to allow the file type to be downloaded (by setting mime types), and then setting up a Response object to return the file to the user.
   
Comments
Espen Harlinn 30-Dec-11 9:22am
   
5'ed!
Dear member

It is not allowed to copy or write any file onto the users system via a web browser app.

Your code will consider this line of code "
string path2 = @"c:\";


as the C drive of the server and not as the C drive of local machine.

Also
fi1.CopyTo(path2);
will copy the file to server itself and not the users machine (and that too when the IIS_WPG has been granted the necessary permissions).
   
v3
Comments
Member-2338430 28-Dec-11 6:22am
   
HOW CAN I WRITE CODE WİTH C# DO YOU HAVE AN EXAMPLE CODE?CAN YOU SHARE ME
This question-[ Copy file from Server to local machine ][^] is very similar to your have a go through the thread.
   
hello ,

you can try bellow worked code.
string filename = "KT_page.xml";
string filesource = Server.MapPath("~/files/") + filename; // server file "KT_page.xml" available in server directory "files"
System.IO.FileInfo fi1 = new System.IO.FileInfo(filesource);
string filedest = System.IO.Path.GetTempPath()+"another_name.xml";
fi1.CopyTo(filedest);
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900