Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
ı 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 28-Dec-11 0:55am
Edited 28-Dec-11 0:57am
v2
Comments
Mika Wendelius at 28-Dec-11 5:57am
   
pre tags added
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Espen Harlinn at 30-Dec-11 9:22am
   
5'ed!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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).
  Permalink  
v3
Comments
Member 2338430 at 28-Dec-11 6:22am
   
HOW CAN I WRITE CODE WİTH C# DO YOU HAVE AN EXAMPLE CODE?CAN YOU SHARE ME
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

This question-[ Copy file from Server to local machine ][^] is very similar to your have a go through the thread.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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);
  Permalink  

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

  Print Answers RSS
0 George Jonsson 175
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 19 Aug 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100